[Home] [Help]
PACKAGE BODY: APPS.AP_WEB_EXPENSE_WF
Source
1 PACKAGE BODY AP_WEB_EXPENSE_WF AS
2 /* $Header: apwxwkfb.pls 120.244.12010000.10 2008/11/26 11:38:03 sodash 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 -----------------------------------------------------------------------
128 FUNCTION GetFlowVersion(p_item_type IN VARCHAR2,
129 p_item_key IN VARCHAR2) RETURN NUMBER
130 ---------------------------------------------------------------------------
131 IS
132 l_version_num NUMBER := 0;
133 BEGIN
134
135 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetFlowVersion');
136
137 l_version_num := WF_ENGINE.GetItemAttrNumber(p_item_type,
138 p_item_key,
139 'VERSION');
140
141 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetFlowVersion');
142
143 RETURN l_version_num;
144
145 EXCEPTION
146 WHEN NO_DATA_FOUND THEN
147 RETURN 0;
148 WHEN OTHERS THEN
149 RETURN 0;
150 END GetFlowVersion;
151
152 ----------------------------------------------------------------------
153 PROCEDURE SetFromRole(
154 p_item_type IN VARCHAR2,
155 p_item_key IN VARCHAR2,
156 p_actid IN NUMBER,
157 p_from_role IN VARCHAR2,
158 p_called_from IN VARCHAR2) IS
159 ----------------------------------------------------------------------
160 l_debug_info VARCHAR2(500);
161 l_role_valid VARCHAR2(1);
162 tvalue varchar2(4000);
163 role_info_tbl wf_directory.wf_local_roles_tbl_type;
164 BEGIN
165
166 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRole');
167
168 l_role_valid := 'Y';
169 tvalue := p_from_role;
170 Wf_Directory.GetRoleInfo2(p_from_role,role_info_tbl);
171 tvalue := role_info_tbl(1).name;
172 -- If not internal name, check for display_name
173 if (tvalue is null) then
174 begin
175 SELECT name
176 INTO tvalue
177 FROM wf_role_lov_vl
178 WHERE upper(display_name) = upper(p_from_role)
179 AND rownum = 1;
180 exception
181 when no_data_found then
182 -- Not displayed or internal role name, error
183 l_role_valid := 'N';
184 end;
185 end if;
186
187 if l_role_valid <> 'N' then
188 ----------------------------------------------------------------
189 l_debug_info := 'Set #FROM_ROLE : called from : ' || p_called_from;
190 ----------------------------------------------------------------
191 WF_ENGINE.SetItemAttrText(p_item_type,
192 p_item_key,
193 '#FROM_ROLE',
194 tvalue);
195 end if;
196
197 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRole');
198
199 EXCEPTION
200 WHEN OTHERS THEN
201 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRole:Called From' ||
202 p_called_from,
203 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
204 raise;
205 END SetFromRole;
206
207 ---------------------------------------------------------------------------
208 PROCEDURE StartExpenseReportProcess(p_report_header_id IN NUMBER,
209 p_preparer_id IN NUMBER,
210 p_employee_id IN NUMBER,
211 p_document_number IN VARCHAR2,
212 p_total IN NUMBER,
213 p_new_total IN NUMBER,
214 p_reimb_curr IN VARCHAR2,
215 p_cost_center IN VARCHAR2,
216 p_purpose IN VARCHAR2,
217 p_approver_id IN NUMBER,
218 p_week_end_date IN DATE,
219 p_workflow_flag IN VARCHAR2,
220 p_submit_from_oie IN VARCHAR2,
221 p_event_raised IN VARCHAR2 DEFAULT 'N') IS
222 ---------------------------------------------------------------------------
223 l_item_type VARCHAR2(100) := 'APEXP';
224 l_item_key VARCHAR2(100) := to_char(p_report_header_id);
225 l_preparer_name wf_users.name%type;
226 l_preparer_display_name wf_users.display_name%type;
227 l_employee_display_name wf_users.display_name%type;
228 l_approver_name wf_users.name%type;
229 l_approver_display_name wf_users.display_name%type;
230 l_emp_cost_center VARCHAR2(240);
231 l_dummy_emp_name VARCHAR2(240);
232 l_emp_num VARCHAR2(30);
233 l_emp_name wf_users.name%type;
234 l_total NUMBER;
235 l_total_dsp VARCHAR2(50);
236 l_new_total_dsp VARCHAR2(50);
237 l_credit_total_dsp VARCHAR2(50);
238 l_credit_total NUMBER;
239 l_url VARCHAR2(1000);
240 l_debug_info VARCHAR2(200);
241 l_employee_project_enabled VARCHAR2(1);
242 C_CreditLineVersion CONSTANT NUMBER := 1;
243 C_WF_Version NUMBER := 0;
244 l_err_name VARCHAR2(30);
245 l_ResubmitReport BOOLEAN := FALSE;
246
247 -- for bug 1652106
248 l_n_org_id NUMBER;
249
250 -- for bug 2069362
251 l_AMEEnabled VARCHAR2(1);
252 l_bAMEProfileDefined BOOLEAN;
253
254 -- Grants Integration
255 l_grants_enabled VARCHAR2(1);
256
257 l_textNameArr Wf_Engine.NameTabTyp;
258 l_textValArr Wf_Engine.TextTabTyp;
259 l_numNameArr Wf_Engine.NameTabTyp;
260 l_numValArr Wf_Engine.NumTabTyp;
261 iNum NUMBER :=0;
262 iText NUMBER :=0;
263
264 --ER 1552747 - withdraw expense report
265 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
266
267 -- Policy Violation
268 l_violation_count NUMBER:=0;
269 l_policy_violation_value VARCHAR2(50);
270 l_policy_violation_defined BOOLEAN;
271
272 l_n_resp_id Number;
273 l_userid VARCHAR2(80);
274 l_card_program_id NUMBER := 0;
275
276 BEGIN
277
278 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartExpenseReportProcess');
279
280 -- org_context should be set while calling icx_sec.validatesession
281 --IF AP_WEB_INFRASTRUCTURE_PKG.ValidateSession(NULL, FALSE, FALSE) THEN
282
283 UpdateHeaderLines(p_report_header_id); --Bug 2777245
284
285 -- Fix 2178792 : Added the below select
286 select nvl(AMT_DUE_CCARD_COMPANY,0)+nvl(AMT_DUE_EMPLOYEE,0)+nvl(MAXIMUM_AMOUNT_TO_APPLY,0)
287 into l_total
288 from ap_expense_report_headers_all
289 where report_header_id = p_report_header_id;
290
291 l_total_dsp := to_char(l_total,
292 FND_CURRENCY.Get_Format_Mask(p_reimb_curr,22));
293 l_new_total_dsp := to_char(p_new_total,
294 FND_CURRENCY.Get_Format_Mask(p_reimb_curr,22));
295 l_credit_total := p_total - p_new_total;
296 l_credit_total_dsp := to_char(l_credit_total,
297 FND_CURRENCY.Get_Format_Mask(p_reimb_curr,22));
298 AP_WEB_PROJECT_PKG.IsSessionProjectEnabled(
299 p_employee_id,
300 FND_PROFILE.VALUE('USER_ID'),
301 l_employee_project_enabled);
302
303 l_ResubmitReport := AP_WEB_DB_EXPRPT_PKG.ResubmitExpenseReport(
304 p_workflow_flag);
305
306 -- Grants Integration
307 IF (GMS_OIE_INT_PKG.IsGrantsEnabled()) THEN
308 l_grants_enabled := 'Y';
309 ELSE
310 l_grants_enabled := 'N';
311 END IF;
312
313 IF (NOT l_ResubmitReport and p_event_raised <> 'Y') THEN
314 BEGIN
315 -- We need to create a process when we are submitting for the first time or
316 -- expense was withdrawn.
317 -- For resubmitting a rejected/returned report, we just need to start up the
318 -- workflow process from the blocked activity.
319
320 --------------------------------------------------
321 l_debug_info := 'Calling WorkFlow Create Process';
322 --------------------------------------------------
323 WF_ENGINE.CreateProcess(l_item_type,
324 l_item_key,
325 'AP_EXPENSE_REPORT_PROCESS');
326 EXCEPTION
327 when others then
328 l_err_name := wf_core.error_name;
329 if (l_err_name = 'WFENG_ITEM_UNIQUE') then
330 -- the workflow process with l_item_key has been created
331 -- previously. we should still allow users to submit the
332 -- same report for bug 2203698.
333 wf_core.clear;
334 else
335 raise;
336 end if;
337 END;
338 END IF;
339
340
341 -- for bug 1652106
342 --------------------------------------------------------------
343 l_debug_info := 'Get Org_ID value ';
344 --------------------------------------------------------------
345
346 /* Bug 2945379 : The org_id retrieved from the table will
347 always be the correct one */
348 -- FND_PROFILE.GET('ORG_ID' , l_n_org_id );
349
350 SELECT org_id
351 INTO l_n_org_id
352 FROM ap_expense_report_headers_all
353 WHERE report_header_id = l_item_key;
354
355
356 -- ORG_ID was added later; therefore, it needs to be tested for upgrade purpose, and
357 -- is not included in the bulk update.
358 begin
359
360 WF_ENGINE.SetItemAttrNumber(l_item_type,
361 l_item_key,
362 'ORG_ID',
363 l_n_Org_ID);
364 exception
365 when others then
366 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
367 -- ORG_ID item attribute doesn't exist, need to add it
368 WF_ENGINE.AddItemAttr(l_item_type, l_item_key, 'ORG_ID');
369 WF_ENGINE.SetItemAttrNumber(l_item_type,
370 l_item_key,
371 'ORG_ID',
372 l_n_Org_ID);
373 else
374 raise;
375 end if;
376
377 end;
378
379
380 begin
381
382 /* Bug 2351528. Need to set the user_key for easier query */
383 WF_ENGINE.SetItemUserKey(l_item_type,
384 l_item_key,
385 p_document_number);
386
387 --------------------------------------------------------------
388 l_debug_info := 'Set User_ID value ';
389 --------------------------------------------------------------
390 WF_ENGINE.SetItemAttrNumber(l_item_type,
391 l_item_key,
392 'USER_ID',
393 FND_PROFILE.VALUE('USER_ID'));
394
395 --------------------------------------------------------------
396 l_debug_info := 'Set Resp_ID value ';
397 --------------------------------------------------------------
398 WF_ENGINE.SetItemAttrNumber(l_item_type,
399 l_item_key,
400 'RESPONSIBILITY_ID',
401 FND_PROFILE.VALUE('RESP_ID'));
402
403 --------------------------------------------------------------
404 l_debug_info := 'Set Resp_Appl_ID value ';
405 --------------------------------------------------------------
406 WF_ENGINE.SetItemAttrNumber(l_item_type,
407 l_item_key,
408 'APPLICATION_ID',
409 FND_PROFILE.VALUE('RESP_APPL_ID'));
410
411 ------------------------------------------------------------
412 l_debug_info := 'Get responsibility id';
413 ------------------------------------------------------------
414 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(l_item_type,
415 l_item_key,
416 'RESPONSIBILITY_ID');
417
418 exception
419 when others then
420 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
421 null;
422 else
423 raise;
424 end if;
425 end;
426
427 ----------------------------------------------------
428 l_debug_info := 'Retrieve profile option AME Enabled?';
429 ----------------------------------------------------
430 FND_PROFILE.GET_SPECIFIC('AME_INSTALLED_FLAG', null, l_n_resp_id, 200, l_AMEEnabled, l_bAMEProfileDefined);
431
432 if l_bAMEProfileDefined then
433 l_AMEEnabled := NVL(l_AMEENABLED,'N'); -- Default to 'N' if null
434 else
435 l_AMEEnabled := 'N';
436 end if;
437
438 WF_ENGINE.SetItemAttrText(l_item_type,
439 l_item_key,
440 'AME_ENABLED',
441 l_AMEEnabled);
442
443 -------------------------------------------------
444 l_debug_info := 'Update Withdraw Message';
445 -------------------------------------------------
446 --ER 1552747 - withdraw expense report
447 if p_workflow_flag = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_WITHDRAW then
448 FND_MESSAGE.SET_NAME('SQLAP','OIE_WITHDRAW_WARNING');
449 l_mess := FND_MESSAGE.GET;
450 WF_ENGINE.SetItemAttrText(l_item_type,
451 l_item_key,
452 'WITHDRAW_WARNING',
453 l_mess);
454 end if;
455
456 ----------------------------------------------------
457 l_debug_info := 'Set Grants Enabled Item Attribute';
458 ----------------------------------------------------
459 WF_ENGINE.SetItemAttrText(l_item_type,
460 l_item_key,
461 'GRANTS_ENABLED',
462 l_grants_enabled);
463
464
465 -------------------------------------------------
466 l_debug_info := 'Set WF Purpose Item Attribute';
467 -------------------------------------------------
468 iText := iText + 1;
469 l_textNameArr(iText) := 'PURPOSE';
470 l_textValArr(iText) := p_purpose;
471
472 ------------------------------------------------------
473 l_debug_info := 'Set LINE_TABLE Item Attribute';
474 ------------------------------------------------------
475
476 iText := iText + 1;
477 l_textNameArr(iText) := 'LINE_TABLE';
478 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key;
479
480 ------------------------------------------------------
481 l_debug_info := 'Set EMP_LINE_TABLE Item Attribute';
482 ------------------------------------------------------
483
484 iText := iText + 1;
485 l_textNameArr(iText) := 'EMP_LINE_TABLE';
486 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key||':'||C_EMP;
487 ----------------------------------------------------------
488 l_debug_info := 'Set WF Expense_Report_ID Item Attribute';
489 ----------------------------------------------------------
490 iNum := iNum + 1;
491 l_numNameArr(iNum) := 'EXPENSE_REPORT_ID';
492 l_numValArr(iNum) := p_report_header_id;
493
494 --------------------------------------------------------
495 l_debug_info := 'Set WF Document_Number Item Attribute';
496 --------------------------------------------------------
497 iText := iText + 1;
498 l_textNameArr(iText) := 'DOCUMENT_NUMBER';
499 l_textValArr(iText) := p_document_number;
500
501 ------------------------------------------------------------
502 l_debug_info := 'Get Name Info Associated With Preparer_Id';
503 ------------------------------------------------------------
504 WF_DIRECTORY.GetUserName('PER',
505 p_preparer_id,
506 l_preparer_name,
507 l_preparer_display_name);
508
509 ----------------------------------------------------------
510 l_debug_info := 'Set the Owner of Workflow Process.';
511 ----------------------------------------------------------
512 WF_ENGINE.SetItemOwner(l_item_type, l_item_key, l_preparer_name);
513
514 ------------------------------------------------------------
515 l_debug_info := 'Get Name Info Associated With Employee_Id';
516 ------------------------------------------------------------
517 WF_DIRECTORY.GetUserName('PER',
518 p_employee_id,
519 l_emp_name,
520 l_employee_display_name);
521
522 ---------------------------------------------------------------------------
523 l_debug_info := 'Get the Employee Cost Center Associated With Preparer_Id';
524 ---------------------------------------------------------------------------
525 AP_WEB_UTILITIES_PKG.GetEmployeeInfo(l_dummy_emp_name,
526 l_emp_num,
527 l_emp_cost_center,
528 p_employee_id);
529
530 ------------------------------------------------------
531 l_debug_info := 'Set WF Preparer_ID Item Attribute';
532 ------------------------------------------------------
533 iNum := iNum + 1;
534 l_numNameArr(iNum) := 'PREPARER_ID';
535 l_numValArr(iNum) := p_preparer_id;
536
537 ------------------------------------------------------
538 l_debug_info := 'Set WF Preparer_Name Item Attribute';
539 ------------------------------------------------------
540 iText := iText + 1;
541 l_textNameArr(iText) := 'PREPARER_NAME';
542 l_textValArr(iText) := l_preparer_name;
543
544 --------------------------------------------------------------
545 l_debug_info := 'Set WF Preparer_Display_Name Item Attribute';
546 --------------------------------------------------------------
547 iText := iText + 1;
548 l_textNameArr(iText) := 'PREPARER_DISPLAY_NAME';
549 l_textValArr(iText) := l_preparer_display_name;
550
551 ------------------------------------------------------
552 l_debug_info := 'Set WF Employee_ID Item Attribute';
553 ------------------------------------------------------
554 iNum := iNum + 1;
555 l_numNameArr(iNum) := 'EMPLOYEE_ID';
556 l_numValArr(iNum) := p_employee_id;
557
558 ------------------------------------------------------
559 l_debug_info := 'Set WF Employee_Name Item Attribute';
560 ------------------------------------------------------
561 iText := iText + 1;
562 l_textNameArr(iText) := 'EMPLOYEE_NAME';
563 l_textValArr(iText) := l_emp_name;
564
565 --------------------------------------------------------------
566 l_debug_info := 'Set WF Preparer_Display_Name Item Attribute';
567 --------------------------------------------------------------
568 iText := iText + 1;
569 l_textNameArr(iText) := 'EMPLOYEE_DISPLAY_NAME';
570 l_textValArr(iText) := l_employee_display_name;
571
572 --------------------------------------------------------------
573 l_debug_info := 'Set CC Payment Due From Item Attribute';
574 --------------------------------------------------------------
575 iText := iText + 1;
576 l_textNameArr(iText) := 'PAYMENT_DUE_FROM';
577
578 IF (NOT AP_WEB_DB_EXPRPT_PKG.getPaymentDueFromReport(p_report_header_id,l_textValArr(iText))) THEN
579 l_debug_info := 'Could not set workflow attribute Payment_Due_From';
580 END IF;
581
582 -------------------------------------------------------------
583 l_debug_info := 'Retrieve and Set Approver Item Attributes If
584 Approver_Id is provided by the user';
585 --------------------------------------------------------------
586
587 -- Be sure to clear these values. If we are resubmitting, we don't want
588 -- the values from the previous process traversal to hang around.
589 l_approver_name := NULL;
590 l_approver_display_name := NULL;
591
592 IF (p_approver_id IS NOT NULL) THEN
593
594 WF_DIRECTORY.GetUserName('PER',
595 p_approver_id,
596 l_approver_name,
597 l_approver_display_name);
598
599 iNum := iNum + 1;
600 l_numNameArr(iNum) := 'APPROVER_ID';
601 l_numValArr(iNum) := p_approver_id;
602
603 iText := iText + 1;
604 l_textNameArr(iText) := 'APPROVER_NAME';
605 l_textValArr(iText) := l_approver_name;
606
607 iText := iText + 1;
608 l_textNameArr(iText) := 'APPROVER_DISPLAY_NAME';
609 l_textValArr(iText) := l_approver_display_name;
610 END IF;
611
612 ---------------------------------------------------------------
613 l_debug_info := 'Set WF (Expense Report) Total Item Attribute';
614 ---------------------------------------------------------------
615 iNum := iNum + 1;
616 l_numNameArr(iNum) := 'TOTAL';
617 l_numValArr(iNum) := l_total;
618
619 ------------------------------------------------------------------------
620 l_debug_info := 'Set WF (Expense Report) Display_Total Item Attribute';
621 ------------------------------------------------------------------------
622 iText := iText + 1;
623 l_textNameArr(iText) := 'DISPLAY_TOTAL';
624 l_textValArr(iText) := l_total_dsp || ' ' || p_reimb_curr;
625
626 -----------------------------------------------------
627 l_debug_info := 'Get Workflow Version Number 0';
628 -----------------------------------------------------
629 C_WF_Version := GetFlowVersion(l_item_type, l_item_key);
630
631 IF (C_WF_Version >= C_CreditLineVersion) THEN
632
633 ---------------------------------------------------------------
634 l_debug_info := 'Set WF (Expense Report) New Expense Total Item Attribute';
635 ---------------------------------------------------------------
636 iNum := iNum + 1;
637 l_numNameArr(iNum) := 'POS_NEW_EXPENSE_TOTAL';
638 l_numValArr(iNum) := p_new_total;
639
640 ------------------------------------------------------------------------
641 l_debug_info := 'Set WF (Expense Report) New Expense Display Total Item Attribute';
642 ------------------------------------------------------------------------
643 iText := iText + 1;
644 l_textNameArr(iText) := 'POS_NEW_EXPENSE_DISPLAY_TOTAL';
645 l_textValArr(iText) := l_new_total_dsp;
646
647 ---------------------------------------------------------------
648 l_debug_info := 'Set WF (Expense Report) Credit Total Item Attribute';
649 ---------------------------------------------------------------
650 iNum := iNum + 1;
651 l_numNameArr(iNum) := 'NEG_CREDIT_TOTAL';
652 l_numValArr(iNum) := l_credit_total;
653
654 ------------------------------------------------------------------------
655 l_debug_info := 'Set WF (Expense Report) Credit Display Total Item Attribute';
656 ------------------------------------------------------------------------
657 iText := iText + 1;
658 l_textNameArr(iText) := 'NEG_CREDIT_DISPLAY_TOTAL';
659 l_textValArr(iText) := l_credit_total_dsp;
660 END IF;
661
662 IF (C_WF_Version >= C_ProjectIntegrationVersion) THEN
663
664 -------------------------------------------------
665 l_debug_info := 'Set WF Week End Date Item Attribute';
666 -------------------------------------------------
667 WF_ENGINE.SetItemAttrDate(l_item_type,
668 l_item_key,
669 'WEEK_END_DATE',
670 p_week_end_date);
671
672 END IF;
673
674 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_11_0_3Version) THEN
675 -------------------------------------------------
676 l_debug_info := 'Set whether employee is project enabled';
677 -------------------------------------------------
678 iText := iText + 1;
679 l_textNameArr(iText) := 'EMPLOYEE_PROJECT_ENABLED';
680 l_textValArr(iText) := l_employee_project_enabled;
681 END IF;
682
683 ---------------------------------------------------------------
684 l_debug_info := 'Set WF (Expense Report) Currency Item Attribute';
685 ---------------------------------------------------------------
686 iText := iText + 1;
687 l_textNameArr(iText) := 'CURRENCY';
688 l_textValArr(iText) := p_reimb_curr;
689
690 -------------------------------------------------------------
691 l_debug_info := 'Set WF Document Cost Center Item Attribute';
692 -------------------------------------------------------------
693 iText := iText + 1;
694 l_textNameArr(iText) := 'DOC_COST_CENTER';
695 l_textValArr(iText) := p_cost_center;
696
697 -------------------------------------------------------------
698 l_debug_info := 'Set WF Employee Cost Center Item Attribute';
699 -------------------------------------------------------------
700 iText := iText + 1;
701 l_textNameArr(iText) := 'EMP_COST_CENTER';
702 l_textValArr(iText) := l_emp_cost_center;
703
704 -------------------------------------------------------------
705 l_debug_info := 'Set Header Attachments';
706 -------------------------------------------------------------
707 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_OIEJ_Version) THEN
708
709 iText := iText + 1;
710 l_textNameArr(iText) := 'HEADER_ATTACHMENTS';
711 l_textValArr(iText) := 'FND:entity=OIE_HEADER_ATTACHMENTS'|| '&' || 'pk1name=REPORT_HEADER_ID'||'&' ||'pk1value=' || l_item_key;
712
713 END IF;
714
715 ----------------------------------------------------
716 l_debug_info := 'Set SUBMIT_FROM_OIE Item Attribute';
717 ----------------------------------------------------
718 WF_ENGINE.SetItemAttrText(l_item_type,
719 l_item_key,
720 'SUBMIT_FROM_OIE',
721 p_submit_from_oie);
722
723 --------------------------------------------------------
724 l_debug_info := 'Call JumpIntoFunction to retrieve URL';
725 --------------------------------------------------------
726 AP_WEB_INFRASTRUCTURE_PKG.JumpIntoFunction(p_report_header_id,
727 'EXPENSE REPORT',
728 l_url);
729
730 -----------------------------------------------------
731 l_debug_info := 'Set EXPENSE DETAILS Item Attribute';
732 -----------------------------------------------------
733
734 -- Be sure to clear these values. If we are resubmitting, we don't want
735 -- the values from the previous process traversal to hang around.
736 iText := iText + 1;
737 l_textNameArr(iText) := 'EXPENSE_DETAILS';
738 l_textValArr(iText) := l_url;
739
740 -----------------------------------------------------
741 l_debug_info := 'Retrieve user id';
742 -----------------------------------------------------
743 AP_WEB_OA_MAINFLOW_PKG.GetUserID(p_employee_id, l_userid);
744
745 ------------------------------------------------------------
746 l_debug_info := 'Retrieve policy profile option';
747 ------------------------------------------------------------
748 FND_PROFILE.get_specific('AP_WEB_POLICY_VIOLATION_SUBMIT', l_userid,
749 l_n_resp_id, 200, l_policy_violation_value, l_policy_violation_defined);
750
751 if l_policy_violation_defined then
752 l_policy_violation_value := NVL(l_policy_violation_value, C_ALLOW_NO_WARNINGS);
753 else
754 l_policy_violation_value := C_ALLOW_NO_WARNINGS;
755 end if;
756
757 --Bug 3581975:Select the policy lines with distribution_line_number > 0.
758 SELECT count(*)
759 INTO l_violation_count
760 FROM ap_pol_violations
761 WHERE report_header_id = p_report_header_id
762 and distribution_line_number > 0;
763
764 ------------------------------------------------------------
765 l_debug_info := 'Do NOT set EMP_VIOLATION_NOTE when policy profile is Approver Only';
766 ------------------------------------------------------------
767 IF (l_violation_count > 0) THEN
768 IF (l_policy_violation_value <> C_ALLOW_NO_WARNINGS) THEN
769 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_VIOLATION_NOTE');
770 l_mess := FND_MESSAGE.GET;
771 iText := iText + 1;
772 l_textNameArr(iText) := 'EMP_VIOLATION_NOTE';
773 l_textValArr(iText) := l_mess;
774 END IF;
775
776 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_VIOLATION_NOTE');
777 l_mess := FND_MESSAGE.GET;
778 iText := iText + 1;
779 l_textNameArr(iText) := 'VIOLATION_NOTE';
780 l_textValArr(iText) := l_mess;
781
782 ELSE
783 iText := iText + 1;
784 l_textNameArr(iText) := 'VIOLATION_NOTE';
785 l_textValArr(iText) := '';
786
787 END IF;
788
789 -----------------------------------------------------
790 l_debug_info := 'Set MILEAGE_NOTE Item Attribute';
791 -----------------------------------------------------
792 iText := iText + 1;
793 l_textNameArr(iText) := 'MILEAGE_NOTE';
794 l_textValArr(iText) := '';
795
796 -----------------------------------------------------
797 l_debug_info := 'Set VERIFY_NOTE Item Attribute';
798 -----------------------------------------------------
799 iText := iText + 1;
800 l_textNameArr(iText) := 'VERIFY_NOTE';
801 l_textValArr(iText) := '';
802
803 -----------------------------------------------------
804 l_debug_info := 'Set all number Attributes';
805 -----------------------------------------------------
806 WF_ENGINE.SetItemAttrNumberArray(l_item_type, l_item_key, l_numNameArr, l_numValArr);
807
808 -----------------------------------------------------
809 l_debug_info := 'Set all text Attributes';
810 -----------------------------------------------------
811 WF_ENGINE.SetItemAttrTextArray(l_item_type, l_item_key, l_textNameArr, l_textValArr);
812
813 BEGIN
814 IF (NOT l_ResubmitReport and p_event_raised <> 'Y') THEN
815
816 ------------------------------------------------------------
817 l_debug_info := 'Start the Expense Report Workflow Process';
818 ------------------------------------------------------------
819 WF_ENGINE.StartProcess(l_item_type,
820 l_item_key);
821
822 ELSIF (l_ResubmitReport) THEN
823
824 ------------------------------------------------------------
825 l_debug_info := 'clear the header/line level return/audit reason/instructions in AERH/AERL';
826 ------------------------------------------------------------
827 AP_WEB_DB_EXPRPT_PKG.clearAuditReturnReasonInstr(p_report_header_id);
828 AP_WEB_DB_EXPLINE_PKG.clearAuditReturnReasonInstr(p_report_header_id);
829
830 ----------------------------------------------------------
831 l_debug_info := 'clear Item Attribute AUDIT_RETURN_REASON';
832 ---------------------------------------------------------
833 WF_ENGINE.SetItemAttrText(l_item_type,
834 l_item_key,
835 'AUDIT_RETURN_REASON',
836 '');
837
838 ----------------------------------------------------------
839 l_debug_info := 'Set Item Attribute AUDIT_INSTRUCTIONS';
840 ---------------------------------------------------------
841 WF_ENGINE.SetItemAttrText(l_item_type,
842 l_item_key,
843 'AUDIT_INSTRUCTIONS',
844 '');
845
846 ------------------------------------------------------------
847 l_debug_info := 'Restart the Expense Report Workflow Process';
848 ------------------------------------------------------------
849 WF_ENGINE.CompleteActivity(l_item_type,
850 l_item_key,
851 'RESUBMIT_BLOCK',
852 '');
853
854
855 END IF;
856
857 EXCEPTION
858 WHEN OTHERS THEN
859 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartExpenseReportProcess',
860 l_item_type, l_item_key, to_char(0), l_debug_info);
861 raise;
862 END;
863 --END IF; --validatesession
864
865 /*Bug 3389386:For Expense report with Both Pay only personal transactions,
866 set the expense_status_code as PAID .
867 */
868 AP_WEB_EXPENSE_WF.SetExpenseStatusCode(p_report_header_id);
869
870 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartExpenseReportProcess');
871
872 EXCEPTION
873 WHEN OTHERS THEN
874
875 -- bug 2203689, set workflow_approved_flag to S so that users can
876 -- re-submit the report without re-entering data again
877
878 -- Bug 3248874 : Also set expense_status_code as NULL.
879 -- Source as NonValidateWebExpense.
880
881 UPDATE ap_expense_report_headers erh
882 SET workflow_approved_flag = 'S',
883 expense_status_code = null,
884 source = 'NonValidatedWebExpense'
885 WHERE report_header_id = p_report_header_id;
886 COMMIT;
887
888
889 IF (SQLCODE <> -20001) THEN
890 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
891 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
892 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'StartExpenseReportProcess');
893 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
894 END IF;
895
896 -- always raise exceptions regardless it from StartExpenseReportProcess
897 -- or other callees
898 APP_EXCEPTION.RAISE_EXCEPTION;
899
900 END StartExpenseReportProcess;
901
902
903 ---------------------------------------------------
904 PROCEDURE GenerateLineErrorsClob(document_id in varchar2,
905 display_type in varchar2,
906 document in out nocopy clob,
907 document_type in out nocopy varchar2,
908 p_is_ccard in boolean,
909 p_is_ap in boolean) IS
910 ---------------------------------------------------
911
912 l_debug_info VARCHAR2(200);
913
914 l_colon NUMBER;
915 l_item_type VARCHAR2(7);
916 l_item_key VARCHAR2(15);
917
918 l_currency VARCHAR2(50);
919 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
920 l_num_lines NUMBER := 0;
921
922 l_n_org_id Number;
923
924 ---------------------------------------------------------
925 -- local procedure to build table header columns
926 ---------------------------------------------------------
927 PROCEDURE GenTableHeader(document in out nocopy clob,
928 p_is_ccard in boolean,
929 p_is_ap in boolean) IS
930
931 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
932 l_title AK_REGIONS_VL.name%TYPE;
933 l_table_header VARCHAR2(2000);
934
935 l_debug_info VARCHAR2(200);
936
937 BEGIN
938 ---------------------------------------------------------
939 l_debug_info := 'Get AP_WEB_WF_SS_ERROR prompts';
940 ---------------------------------------------------------
941 AP_WEB_DISC_PKG.getPrompts(200,'AP_WEB_WF_SS_ERROR', l_title, l_prompts);
942
943 ---------------------------------------------------------
944 l_debug_info := 'Build the table column headers for sysadmin/preparer';
945 ---------------------------------------------------------
946 if (p_is_ccard = true) then
947 l_table_header := indent_start || table_title_start || l_prompts(2) || table_title_end;
948 elsif (p_is_ccard = false) then
949 l_table_header := indent_start || table_title_start || l_prompts(3) || table_title_end;
950 end if;
951
952 l_table_header := l_table_header || table_start;
953 l_table_header := l_table_header || tr_start;
954 -- display Line Number
955 l_table_header := l_table_header || th_select || l_prompts(4) || td_end;
956 -- display Date
957 l_table_header := l_table_header || th_text || l_prompts(5) || td_end;
958 -- display Expense Type
959 l_table_header := l_table_header || th_text || l_prompts(6) || td_end;
960 -- display Amount
961 l_table_header := l_table_header || th_number || l_prompts(7) ||' (' || l_currency || ')' || td_end;
962
963 ---------------------------------------------------------
964 l_debug_info := 'Add the Reason column to the Sys Admin table';
965 ---------------------------------------------------------
966 if (p_is_ap = true) then
967 l_table_header := l_table_header || th_text || l_prompts(8) || td_end;
968 end if;
969
970 l_table_header := l_table_header || tr_end;
971
972 WF_NOTIFICATION.WriteToClob(document, l_table_header);
973
974 EXCEPTION
975 WHEN OTHERS THEN
976 IF (SQLCODE <> -20001) THEN
977 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
978 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
979 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'GenTableHeader');
980 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
981 END IF;
982 APP_EXCEPTION.RAISE_EXCEPTION;
983
984 END GenTableHeader;
985
986 ---------------------------------------------------------
987 -- local procedure to build table rows
988 ---------------------------------------------------------
989 PROCEDURE GenTableRows(document in out nocopy clob,
990 p_is_ccard in boolean,
991 p_is_ap in boolean) IS
992
993 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
994 l_title AK_REGIONS_VL.name%TYPE;
995
996 l_table_row VARCHAR2(2000);
997 l_line_num NUMBER := 0;
998
999 ExpenseReportLinesCursor AP_WEB_DB_EXPLINE_PKG.XpenseLineAcctCursor;
1000 V_DistLineNumber AP_WEB_DB_EXPLINE_PKG.expLines_distLineNum;
1001 l_report_distribution_id AP_WEB_DB_EXPDIST_PKG.expDist_REPORT_DISTRIBUTION_ID;
1002 V_StartExpenseDate AP_WEB_DB_EXPLINE_PKG.expLines_startExpDate;
1003 V_Amount AP_WEB_DB_EXPLINE_PKG.expLines_amount;
1004 V_ExpenseType AP_EXPENSE_REPORT_PARAMS.web_friendly_prompt%TYPE;
1005 V_CreditCardTrxID AP_WEB_DB_EXPLINE_PKG.expLines_crdCardTrxID;
1006 V_ProjectID AP_WEB_DB_EXPLINE_PKG.expLines_projID;
1007 V_TaskID AP_WEB_DB_EXPLINE_PKG.expLines_taskID;
1008 -- Grants Integration
1009 V_AwardID GMS_OIE_INT_PKG.gms_awardId;
1010 V_AwardSetID NUMBER := NULL;
1011 V_ExpenditureItemDate AP_WEB_DB_EXPLINE_PKG.expLines_expendItemDate;
1012 V_ExpenditureType AP_WEB_DB_EXPLINE_PKG.expLines_expendType;
1013 V_PAQuantity AP_WEB_DB_EXPLINE_PKG.expLines_paQuantity;
1014 V_ExpenditureOrganizationID AP_WEB_DB_EXPLINE_PKG.expLines_expOrgID;
1015 V_WebParamID AP_WEB_DB_EXPLINE_PKG.expLines_webParamID;
1016 V_AdjustmentReason AP_WEB_DB_EXPLINE_PKG.expLines_adjReason;
1017 V_CategoryCode AP_WEB_DB_EXPLINE_PKG.expLines_categorycode;
1018 V_FlexConcactenated AP_EXPENSE_REPORT_PARAMS.flex_concactenated%TYPE;
1019 V_LineAttributeCategory AP_WEB_DB_EXPLINE_PKG.expLines_attrCategory;
1020 V_LineAttribute1 AP_WEB_DB_EXPLINE_PKG.expLines_attr1;
1021 V_LineAttribute2 AP_WEB_DB_EXPLINE_PKG.expLines_attr2;
1022 V_LineAttribute3 AP_WEB_DB_EXPLINE_PKG.expLines_attr3;
1023 V_LineAttribute4 AP_WEB_DB_EXPLINE_PKG.expLines_attr4;
1024 V_LineAttribute5 AP_WEB_DB_EXPLINE_PKG.expLines_attr5;
1025 V_LineAttribute6 AP_WEB_DB_EXPLINE_PKG.expLines_attr6;
1026 V_LineAttribute7 AP_WEB_DB_EXPLINE_PKG.expLines_attr7;
1027 V_LineAttribute8 AP_WEB_DB_EXPLINE_PKG.expLines_attr8;
1028 V_LineAttribute9 AP_WEB_DB_EXPLINE_PKG.expLines_attr9;
1029 V_LineAttribute10 AP_WEB_DB_EXPLINE_PKG.expLines_attr10;
1030 V_LineAttribute11 AP_WEB_DB_EXPLINE_PKG.expLines_attr11;
1031 V_LineAttribute12 AP_WEB_DB_EXPLINE_PKG.expLines_attr12;
1032 V_LineAttribute13 AP_WEB_DB_EXPLINE_PKG.expLines_attr13;
1033 V_LineAttribute14 AP_WEB_DB_EXPLINE_PKG.expLines_attr14;
1034 V_LineAttribute15 AP_WEB_DB_EXPLINE_PKG.expLines_attr15;
1035 V_LineFlexConcat AP_WEB_DB_EXPLINE_PKG.expLines_LineFlexConcat;
1036 V_APValidationError AP_WEB_DB_EXPLINE_PKG.expLines_APValidationError;
1037 V_ReportLineId AP_WEB_DB_EXPLINE_PKG.expLines_report_line_id;
1038
1039
1040 l_debug_info VARCHAR2(200);
1041
1042 BEGIN
1043
1044 ------------------------------------------------------------------------
1045 l_debug_info := 'calling AP_WEB_DB_EXPLINE_PKG.GetExpDistAcctCursor';
1046 ------------------------------------------------------------------------
1047 IF (AP_WEB_DB_EXPLINE_PKG.GetExpDistAcctCursor(l_report_header_id,
1048 ExpenseReportLinesCursor)) THEN
1049
1050 LOOP
1051 FETCH ExpenseReportLinesCursor INTO
1052 V_DistLineNumber,
1053 l_report_distribution_id,
1054 V_StartExpenseDate,
1055 V_Amount,
1056 V_ExpenseType,
1057 V_CreditCardTrxID,
1058 V_ProjectID,
1059 V_TaskID,
1060 V_AwardID,
1061 V_ExpenditureItemDate,
1062 V_ExpenditureType,
1063 V_PAQuantity,
1064 V_ExpenditureOrganizationID,
1065 V_WebParamID,
1066 V_AdjustmentReason,
1067 V_FlexConcactenated,
1068 V_CategoryCode,
1069 V_LineAttributeCategory,
1070 V_LineAttribute1,
1071 V_LineAttribute2,
1072 V_LineAttribute3,
1073 V_LineAttribute4,
1074 V_LineAttribute5,
1075 V_LineAttribute6,
1076 V_LineAttribute7,
1077 V_LineAttribute8,
1078 V_LineAttribute9,
1079 V_LineAttribute10,
1080 V_LineAttribute11,
1081 V_LineAttribute12,
1082 V_LineAttribute13,
1083 V_LineAttribute14,
1084 V_LineAttribute15,
1085 V_LineFlexConcat,
1086 V_APValidationError,
1087 V_ReportLineId;
1088 EXIT WHEN ExpenseReportLinesCursor%NOTFOUND;
1089
1090 ---------------------------------------------------------
1091 l_debug_info := 'Build the row cells for sysadmin/preparer';
1092 ---------------------------------------------------------
1093 if (((p_is_ccard = true and V_CreditCardTrxID is not null) or
1094 (p_is_ccard = false and V_CreditCardTrxID is null)) and
1095 V_APValidationError is not null) then
1096
1097 l_line_num := l_line_num + 1;
1098
1099 l_table_row := tr_start;
1100 l_table_row := l_table_row || td_select || to_char(l_line_num) || td_end;
1101 l_table_row := l_table_row || td_text || V_StartExpenseDate || td_end;
1102 l_table_row := l_table_row || td_text || V_ExpenseType || td_end;
1103 l_table_row := l_table_row || td_number || to_char(V_Amount, FND_CURRENCY.Get_Format_Mask(l_currency,22)) || td_end;
1104
1105 ---------------------------------------------------------
1106 l_debug_info := 'Add the Reason column to the Sys Admin table';
1107 ---------------------------------------------------------
1108 if (p_is_ap = true) then
1109 l_table_row := l_table_row || td_text || V_APValidationError || td_end;
1110 end if;
1111
1112 l_table_row := l_table_row || tr_end;
1113
1114 WF_NOTIFICATION.WriteToClob(document, l_table_row);
1115 end if;
1116
1117 END LOOP; /* ExpenseReportLinesCursor */
1118
1119 END IF; /* GetExpDistAcctCursor */
1120
1121 if ExpenseReportLinesCursor%isopen then
1122 CLOSE ExpenseReportLinesCursor;
1123 end if;
1124
1125 l_table_row := table_end || indent_end;
1126
1127 WF_NOTIFICATION.WriteToClob(document, l_table_row);
1128
1129 EXCEPTION
1130 WHEN OTHERS THEN
1131 IF (SQLCODE <> -20001) THEN
1132 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
1133 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1134 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'GenTableRows');
1135 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
1136 END IF;
1137 APP_EXCEPTION.RAISE_EXCEPTION;
1138
1139 END GenTableRows;
1140
1141 BEGIN
1142
1143 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateLineErrorsClob');
1144
1145 ------------------------------------------------------------
1146 l_debug_info := 'Decode document_id';
1147 ------------------------------------------------------------
1148 l_colon := instrb(document_id, ':');
1149 l_item_type := substrb(document_id, 1, l_colon - 1);
1150 l_item_key := substrb(document_id, l_colon + 1);
1151
1152 ----------------------------------------------------
1153 l_debug_info := 'Retrieve Currency Item Attribute';
1154 ----------------------------------------------------
1155 l_currency := WF_ENGINE.GetItemAttrText(l_item_type,
1156 l_item_key,
1157 'CURRENCY');
1158
1159 ------------------------------------------------------------
1160 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
1161 ------------------------------------------------------------
1162 l_report_header_id := WF_ENGINE.GetItemAttrNumber(l_item_type,
1163 l_item_key,
1164 'EXPENSE_REPORT_ID');
1165
1166 --------------------------------------------
1167 l_debug_info := 'Get Org Id';
1168 --------------------------------------------
1169 begin
1170
1171 l_n_org_id := WF_ENGINE.GetItemAttrNumber(l_item_type,
1172 l_item_key,
1173 'ORG_ID');
1174 exception
1175 when others then
1176 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
1177 -- ORG_ID item attribute doesn't exist, need to add it
1178 WF_ENGINE.AddItemAttr(l_item_type, l_item_key, 'ORG_ID');
1179 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
1180 to_number(l_item_key),
1181 l_n_org_id) <> TRUE ) THEN
1182 l_n_org_id := NULL;
1183 END IF;
1184
1185 WF_ENGINE.SetItemAttrNumber(l_item_type,
1186 l_item_key,
1187 'ORG_ID',
1188 l_n_org_ID);
1189 else
1190 raise;
1191 end if;
1192
1193 end;
1194
1195 -- MOAC UPTAKE --
1196 -- Should not have to initialize the org context
1197 -- This is done via callbackfunction()
1198 /*--------------------
1199 if (l_n_org_id is not null) then
1200 fnd_client_info.set_org_context(l_n_org_id);
1201 else
1202 -- Report was submitted before org_id being added, hence org_id
1203 -- item attributes hasn't been set yet. Need to get it from
1204 -- report header
1205 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(to_number(l_item_key), l_n_org_id) <> TRUE ) THEN
1206 l_n_org_id := NULL;
1207 END IF;
1208
1209 IF (l_n_org_id is not null) then
1210 fnd_client_info.set_org_context(l_n_org_id);
1211 END IF;
1212 end if; -- l_n_org_id
1213 ----------------------*/
1214
1215 if (p_is_ccard) then
1216
1217 ------------------------------------------------------------
1218 l_debug_info := 'Checking number of credit card lines with errors';
1219 ------------------------------------------------------------
1220 select count(*)
1221 into l_num_lines
1222 from ap_expense_report_lines
1223 where report_header_id = l_report_header_id
1224 and credit_card_trx_id is not null
1225 and ap_validation_error is not null;
1226
1227 if (l_num_lines = 0) then
1228 return;
1229 end if;
1230
1231 else
1232
1233 ------------------------------------------------------------
1234 l_debug_info := 'Checking number of cash lines with errors';
1235 ------------------------------------------------------------
1236 select count(*)
1237 into l_num_lines
1238 from ap_expense_report_lines
1239 where report_header_id = l_report_header_id
1240 and credit_card_trx_id is null
1241 and ap_validation_error is not null;
1242
1243 if (l_num_lines = 0) then
1244 return;
1245 end if;
1246
1247 end if;
1248
1249 GenTableHeader(document, p_is_ccard, p_is_ap);
1250 GenTableRows(document, p_is_ccard, p_is_ap);
1251
1252 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateLineErrorsClob');
1253
1254 EXCEPTION
1255 WHEN OTHERS THEN
1256 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateLineErrorsClob',
1257 document_id, l_debug_info);
1258 raise;
1259 END GenerateLineErrorsClob;
1260
1261 ---------------------------------------------------
1262 PROCEDURE CashLineErrorsAP(document_id in varchar2,
1263 display_type in varchar2,
1264 document in out nocopy clob,
1265 document_type in out nocopy varchar2) IS
1266 ---------------------------------------------------
1267
1268 l_debug_info VARCHAR2(200);
1269
1270 BEGIN
1271
1272 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CashLineErrorsAP');
1273
1274 GenerateLineErrorsClob(document_id,
1275 display_type,
1276 document,
1277 document_type,
1278 p_is_ccard => false,
1279 p_is_ap => true);
1280
1281 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CashLineErrorsAP');
1282
1283 EXCEPTION
1284 WHEN OTHERS THEN
1285 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CashLineErrorsAP',
1286 document_id, l_debug_info);
1287 raise;
1288 END CashLineErrorsAP;
1289
1290 ---------------------------------------------------
1291 PROCEDURE CashLineErrorsPreparer(document_id in varchar2,
1292 display_type in varchar2,
1293 document in out nocopy clob,
1294 document_type in out nocopy varchar2) IS
1295 ---------------------------------------------------
1296
1297 l_debug_info VARCHAR2(200);
1298
1299 BEGIN
1300
1301 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CashLineErrorsPreparer');
1302
1303 GenerateLineErrorsClob(document_id,
1304 display_type,
1305 document,
1306 document_type,
1307 p_is_ccard => false,
1308 p_is_ap => false);
1309
1310 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CashLineErrorsPreparer');
1311
1312 EXCEPTION
1313 WHEN OTHERS THEN
1314 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CashLineErrorsPreparer',
1315 document_id, l_debug_info);
1316 raise;
1317 END CashLineErrorsPreparer;
1318
1319 ---------------------------------------------------
1320 PROCEDURE CCardLineErrorsAP(document_id in varchar2,
1321 display_type in varchar2,
1322 document in out nocopy clob,
1323 document_type in out nocopy varchar2) IS
1324 ---------------------------------------------------
1325
1326 l_debug_info VARCHAR2(200);
1327
1328 BEGIN
1329
1330 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CCardLineErrorsAP');
1331
1332 GenerateLineErrorsClob(document_id,
1333 display_type,
1334 document,
1335 document_type,
1336 p_is_ccard => true,
1337 p_is_ap => true);
1338
1339 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CCardLineErrorsAP');
1340
1341 EXCEPTION
1342 WHEN OTHERS THEN
1343 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CCardLineErrorsAP',
1344 document_id, l_debug_info);
1345 raise;
1346 END CCardLineErrorsAP;
1347
1348 ---------------------------------------------------
1349 PROCEDURE CCardLineErrorsPreparer(document_id in varchar2,
1350 display_type in varchar2,
1351 document in out nocopy clob,
1352 document_type in out nocopy varchar2) IS
1353 ---------------------------------------------------
1354
1355 l_debug_info VARCHAR2(200);
1356
1357 BEGIN
1358
1359 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CCardLineErrorsPreparer');
1360
1361 GenerateLineErrorsClob(document_id,
1362 display_type,
1363 document,
1364 document_type,
1365 p_is_ccard => true,
1366 p_is_ap => false);
1367
1368 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CCardLineErrorsPreparer');
1369
1370 EXCEPTION
1371 WHEN OTHERS THEN
1372 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CCardLineErrorsPreparer',
1373 document_id, l_debug_info);
1374 raise;
1375 END CCardLineErrorsPreparer;
1376
1377
1378
1379
1380
1381 ---------------------------------------------------
1382 PROCEDURE ResetAPValidationAttrValues(p_item_type IN VARCHAR2,
1383 p_item_key IN VARCHAR2,
1384 p_actid IN NUMBER)
1385 ---------------------------------------------------
1386 IS
1387 --
1388 -- Reset the AP Validation attribute values which are not set explicitly by
1389 -- StartExpenseReportProcess before the returned report is resubmitted.
1390 -- We need to clear these because we will be revisiting nodes in the process.
1391 --
1392
1393 l_textNameArr Wf_Engine.NameTabTyp;
1394 l_textValArr Wf_Engine.TextTabTyp;
1395 iText NUMBER :=0;
1396
1397 l_report_header_id NUMBER;
1398 C_WF_Version NUMBER := 0;
1399
1400 l_debug_info VARCHAR2(200);
1401
1402 BEGIN
1403
1404 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetAPValidationAttrValues');
1405
1406 ----------------------------------------------------------------
1407 l_debug_info := 'Unset Header and Setup errors';
1408 -----------------------------------------------------------------
1409 iText := iText + 1;
1410 l_textNameArr(iText) := 'HEADER_ERRORS';
1411 l_textValArr(iText) := '';
1412
1413 ------------------------------------------------------------
1414 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
1415 ------------------------------------------------------------
1416 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
1417 p_item_key,
1418 'EXPENSE_REPORT_ID');
1419
1420 ------------------------------------------------------
1421 l_debug_info := 'Get version of Workflow';
1422 ------------------------------------------------------
1423 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
1424
1425 ------------------------------------------------------
1426 l_debug_info := 'Set GEN_HEADER_ERRORS Item Attribute';
1427 ------------------------------------------------------
1428 iText := iText + 1;
1429 l_textNameArr(iText) := 'GEN_HEADER_ERRORS';
1430 l_textValArr(iText) := 'plsql:AP_WEB_EXPENSE_WF.GenerateHeaderErrors/'||p_item_type||':'||p_item_key;
1431
1432 ------------------------------------------------------
1433 l_debug_info := 'Set CASH_LINE_ERRORS_AP Item Attribute';
1434 ------------------------------------------------------
1435 iText := iText + 1;
1436 l_textNameArr(iText) := 'CASH_LINE_ERRORS_AP';
1437 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.CashLineErrorsAP/'||p_item_type||':'||p_item_key;
1438
1439 ------------------------------------------------------
1440 l_debug_info := 'Set CASH_LINE_ERRORS_PREPARER Item Attribute';
1441 ------------------------------------------------------
1442 iText := iText + 1;
1443 l_textNameArr(iText) := 'CASH_LINE_ERRORS_PREPARER';
1444 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.CashLineErrorsPreparer/'||p_item_type||':'||p_item_key;
1445
1446 ------------------------------------------------------
1447 l_debug_info := 'Set CCARD_LINE_ERRORS_AP Item Attribute';
1448 ------------------------------------------------------
1449 iText := iText + 1;
1450 l_textNameArr(iText) := 'CCARD_LINE_ERRORS_AP';
1451 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.CCardLineErrorsAP/'||p_item_type||':'||p_item_key;
1452
1453 ------------------------------------------------------
1454 l_debug_info := 'Set CCARD_LINE_ERRORS_PREPARER Item Attribute';
1455 ------------------------------------------------------
1456 iText := iText + 1;
1457 l_textNameArr(iText) := 'CCARD_LINE_ERRORS_PREPARER';
1458 l_textValArr(iText) := 'plsqlclob:AP_WEB_EXPENSE_WF.CCardLineErrorsPreparer/'||p_item_type||':'||p_item_key;
1459
1460 ----------------------------------------------------------------
1461 l_debug_info := 'Reset AP Validation errors';
1462 -----------------------------------------------------------------
1463 AP_WEB_DB_EXPLINE_PKG.ResetAPValidationErrors(l_report_header_id);
1464
1465 ----------------------------------------------------------------
1466 l_debug_info := 'Unset Is Default Cost Center Used?';
1467 -----------------------------------------------------------------
1468 iText := iText + 1;
1469 l_textNameArr(iText) := 'IS_DEFAULT_COST_CENTER_USED';
1470 l_textValArr(iText) := '';
1471
1472 ----------------------------------------------------------------
1473 l_debug_info := 'Unset Is Projects Expense Report?';
1474 -----------------------------------------------------------------
1475 iText := iText + 1;
1476 l_textNameArr(iText) := 'IS_PROJECTS_REPORT';
1477 l_textValArr(iText) := '';
1478
1479 ----------------------------------------------------------------
1480 l_debug_info := 'Unset WF Administrators Note';
1481 -----------------------------------------------------------------
1482 iText := iText + 1;
1483 l_textNameArr(iText) := 'WF_ADMIN_NOTE';
1484 l_textValArr(iText) := '';
1485
1486 ----------------------------------------------------------------
1487 l_debug_info := 'Unset EXP_ALLOCATION_ERRORS';
1488 -----------------------------------------------------------------
1489 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_OIEJ_Version) THEN
1490 iText := iText + 1;
1491 l_textNameArr(iText) := 'EXP_ALLOCATION_ERRORS';
1492 l_textValArr(iText) := '';
1493 END IF;
1494
1495 -----------------------------------------------------
1496 l_debug_info := 'Set all text Attributes';
1497 -----------------------------------------------------
1498 WF_ENGINE.SetItemAttrTextArray(p_item_type, p_item_key, l_textNameArr, l_textValArr);
1499
1500
1501 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetAPValidationAttrValues');
1502
1503 EXCEPTION
1504 WHEN OTHERS THEN
1505 NULL;
1506 END ResetAPValidationAttrValues;
1507
1508 ------------------------------------------------------------------------
1509 PROCEDURE APValidateExpenseReport(p_item_type IN VARCHAR2,
1510 p_item_key IN VARCHAR2,
1511 p_actid IN NUMBER,
1512 p_funmode IN VARCHAR2,
1513 p_result OUT NOCOPY VARCHAR2) IS
1514 ------------------------------------------------------------------------
1515 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
1516
1517 l_emp_cost_center VARCHAR2(240);
1518 l_doc_cost_center VARCHAR2(240);
1519
1520 l_header_errors VARCHAR2(2000) := NULL;
1521 l_other_errors VARCHAR2(2000) := NULL;
1522 l_exp_alloc_errors VARCHAR2(2000) := NULL;
1523 l_num_line_errors NUMBER := 0;
1524
1525 l_yes VARCHAR2(80);
1526 l_no VARCHAR2(80);
1527
1528 l_debug_info VARCHAR2(200);
1529 C_WF_Version NUMBER := 0;
1530
1531
1532 BEGIN
1533
1534 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start APValidateExpenseReport');
1535
1536 IF (p_funmode = 'RUN') THEN
1537
1538 ------------------------------------------------------------
1539 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
1540 ------------------------------------------------------------
1541 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
1542 p_item_key,
1543 'EXPENSE_REPORT_ID');
1544
1545 ----------------------------------------------------------------
1546 l_debug_info := 'Reset AP Validation Attributes';
1547 ----------------------------------------------------------------
1548 ResetAPValidationAttrValues(p_item_type,
1549 p_item_key,
1550 p_actid);
1551
1552 ---------------------------------------
1553 l_debug_info := 'Call DoAPValidation';
1554 ---------------------------------------
1555 DoAPValidation(p_item_type,
1556 p_item_key,
1557 l_report_header_id);
1558
1559 ------------------------------------------------------------
1560 l_debug_info := 'Retrieve HEADER_ERRORS Item Attribute';
1561 ------------------------------------------------------------
1562 l_header_errors := WF_ENGINE.GetItemAttrText(p_item_type,
1563 p_item_key,
1564 'HEADER_ERRORS');
1565 if (l_header_errors IS NOT NULL) then
1566 WF_ENGINE.SetItemAttrText(p_item_type,
1567 p_item_key,
1568 'HEADER_ERRORS',
1569 l_header_errors || '<br>');
1570 end if;
1571
1572 ------------------------------------------------------------
1573 l_debug_info := 'Retrieve OTHER_ERRORS Item Attribute';
1574 ------------------------------------------------------------
1575 l_other_errors := WF_ENGINE.GetItemAttrText(p_item_type,
1576 p_item_key,
1577 'OTHER_ERRORS');
1578 if (l_other_errors IS NOT NULL) then
1579 WF_ENGINE.SetItemAttrText(p_item_type,
1580 p_item_key,
1581 'OTHER_ERRORS',
1582 l_other_errors || '<br>');
1583 end if;
1584
1585 ------------------------------------------------------
1586 l_debug_info := 'Get version of Workflow';
1587 ------------------------------------------------------
1588 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
1589
1590 ------------------------------------------------------------
1591 l_debug_info := 'Retrieve EXP_ALLOCATION_ERRORS Item Attribute';
1592 ------------------------------------------------------------
1593 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_OIEJ_Version) THEN
1594 l_exp_alloc_errors := WF_ENGINE.GetItemAttrText(p_item_type,
1595 p_item_key,
1596 'EXP_ALLOCATION_ERRORS',
1597 true);
1598 if (l_exp_alloc_errors IS NOT NULL) then
1599 WF_ENGINE.SetItemAttrText(p_item_type,
1600 p_item_key,
1601 'EXP_ALLOCATION_ERRORS',
1602 l_exp_alloc_errors );
1603 end if;
1604 END IF;
1605
1606 ----------------------------------------------------------------
1607 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
1608 ----------------------------------------------------------------
1609 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
1610 p_item_key,
1611 'EMP_COST_CENTER');
1612
1613 ----------------------------------------------------------------
1614 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
1615 ----------------------------------------------------------------
1616 l_doc_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
1617 p_item_key,
1618 'DOC_COST_CENTER');
1619
1620 ----------------------------------------------------------------
1621 l_debug_info := 'Set IS_DEFAULT_COST_CENTER_USED';
1622 ----------------------------------------------------------------
1623 if (l_emp_cost_center = l_doc_cost_center) then
1624
1625 SELECT fndl.meaning
1626 INTO l_yes
1627 FROM FND_LOOKUPS fndl
1628 WHERE fndl.LOOKUP_TYPE = C_YES_NO
1629 AND fndl.LOOKUP_CODE = C_Y;
1630
1631 WF_ENGINE.SetItemAttrText(p_item_type,
1632 p_item_key,
1633 'IS_DEFAULT_COST_CENTER_USED',
1634 l_yes);
1635 else
1636
1637 SELECT fndl.meaning
1638 INTO l_no
1639 FROM FND_LOOKUPS fndl
1640 WHERE fndl.LOOKUP_TYPE = C_YES_NO
1641 AND fndl.LOOKUP_CODE = C_N;
1642
1643 WF_ENGINE.SetItemAttrText(p_item_type,
1644 p_item_key,
1645 'IS_DEFAULT_COST_CENTER_USED',
1646 l_no);
1647 end if;
1648
1649 ----------------------------------------------------------------
1650 l_debug_info := 'Get number of line errors';
1651 -----------------------------------------------------------------
1652 select count(*)
1653 into l_num_line_errors
1654 from ap_expense_report_lines
1655 where report_header_id = l_report_header_id
1656 and ap_validation_error is not null;
1657
1658 ----------------------------------------------------------------
1659 l_debug_info := 'Return Pass If No Header or Line Errors,
1660 otherwise Return Fail';
1661 -----------------------------------------------------------------
1662 IF (l_header_errors IS NULL AND l_num_line_errors = 0 AND l_other_errors IS NULL) then
1663 p_result := 'COMPLETE:AP_PASS';
1664 ELSIF (l_exp_alloc_errors is not null) THEN
1665 p_result := 'COMPLETE:AP_FAIL_EXP_ALLOC';
1666 ELSE
1667 p_result := 'COMPLETE:AP_FAIL';
1668 /*
1669 The following item attributes are also set:
1670 1. Cost Center Entered = DOC_COST_CENTER
1671 This is already set in the WF process
1672 2. IS_DEFAULT_COST_CENTER_USED = 'Yes'/'No'
1673 This is set in APValidateExpenseReport()
1674 3. IS_PROJECTS_REPORT = 'Yes' if report contains Projects lines
1675 This is set in DoAPValidation()
1676 */
1677
1678 END IF;
1679
1680 ELSIF (p_funmode = 'CANCEL') THEN
1681
1682 p_result := 'COMPLETE';
1683
1684 END IF;
1685
1686 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end APValidateExpenseReport');
1687
1688 EXCEPTION
1689 WHEN OTHERS THEN
1690 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'APValidateExpenseReport',
1691 p_item_type, p_item_key, to_char(0), l_debug_info || FND_MESSAGE.GET);
1692 raise;
1693 END APValidateExpenseReport;
1694
1695 ------------------------------------------------------------------------
1696 PROCEDURE AddToWFSSError(p_error_message IN OUT NOCOPY VARCHAR2,
1697 p_new_error IN VARCHAR2) IS
1698 ------------------------------------------------------------------------
1699 l_exceed_error_msg VARCHAR2(80) := 'Error message has exceeded 2000 char limit.';
1700 BEGIN
1701 -- check to see if exceed error message has already been appended
1702 if (instrb(p_error_message, l_exceed_error_msg) = 0) then
1703 if ((lengthb(p_error_message) + lengthb(p_new_error) + lengthb(l_exceed_error_msg)) > 1950) then
1704 p_error_message := p_error_message || l_exceed_error_msg;
1705 else
1706 p_error_message := p_error_message || p_new_error;
1707 end if;
1708 end if;
1709 EXCEPTION
1710 WHEN OTHERS THEN
1711 IF (SQLCODE <> -20001) THEN
1712 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
1713 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1714 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'AddToWFSSError');
1715 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_exceed_error_msg);
1716 END IF;
1717 APP_EXCEPTION.RAISE_EXCEPTION;
1718
1719 END AddToWFSSError;
1720
1721 ----------------------------------------------------------------------
1722 PROCEDURE AddToHeaderErrors(p_item_type IN VARCHAR2,
1723 p_item_key IN VARCHAR2,
1724 p_header_error IN VARCHAR2) IS
1725 ----------------------------------------------------------------------
1726
1727 l_header_errors VARCHAR2(2000) := NULL;
1728
1729 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
1730 l_title AK_REGIONS_VL.name%TYPE;
1731
1732 l_debug_info VARCHAR2(2000);
1733
1734 BEGIN
1735
1736 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AddToHeaderErrors');
1737
1738 ---------------------------------------------------------
1739 l_debug_info := 'Add to Header Errors';
1740 ---------------------------------------------------------
1741 l_header_errors := WF_ENGINE.GetItemAttrText(p_item_type,
1742 p_item_key,
1743 'HEADER_ERRORS');
1744 ---------------------------------------------------------
1745 l_debug_info := 'Check to see if error title needed';
1746 ---------------------------------------------------------
1747 if (l_header_errors IS NULL) then
1748 ---------------------------------------------------------
1749 l_debug_info := 'Add font tag';
1750 ---------------------------------------------------------
1751 l_header_errors := startOraFieldTextFont;
1752 else
1753 l_header_errors := l_header_errors || '<br>';
1754 end if;
1755
1756 AddToWFSSError(l_header_errors, p_header_error);
1757
1758 l_header_errors := l_header_errors || endOraFieldTextFont;
1759
1760 WF_ENGINE.SetItemAttrText(p_item_type,
1761 p_item_key,
1762 'HEADER_ERRORS',
1763 l_header_errors);
1764
1765 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AddToHeaderErrors');
1766
1767 EXCEPTION
1768 WHEN OTHERS THEN
1769 IF (SQLCODE <> -20001) THEN
1770 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
1771 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1772 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'AddToHeaderErrors');
1773 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
1774 END IF;
1775 APP_EXCEPTION.RAISE_EXCEPTION;
1776
1777 END AddToHeaderErrors;
1778
1779
1780 ----------------------------------------------------------------------
1781 PROCEDURE HandleInvalidDistCCID(p_report_header_id IN AP_EXPENSE_REPORT_HEADERS.report_header_id%TYPE,
1782 p_report_distribution_id IN AP_WEB_DB_EXPDIST_PKG.expDist_REPORT_DISTRIBUTION_ID,
1783 p_payment_due IN VARCHAR2,
1784 p_exp_type_parameter_id IN AP_WEB_DB_EXPLINE_PKG.expLines_webParamID,
1785 p_personalParameterId IN AP_WEB_DB_EXPLINE_PKG.expLines_webParamID,
1786 p_CategoryCode IN AP_WEB_DB_EXPLINE_PKG.expLines_categorycode,
1787 p_default_emp_segments IN AP_OIE_KFF_SEGMENTS_T,
1788 p_dist_new_segments IN AP_OIE_KFF_SEGMENTS_T,
1789 p_ReportLineId IN AP_WEB_DB_EXPLINE_PKG.expLines_report_line_id,
1790 p_exp_dist_ccid IN AP_WEB_DB_EXPLINE_PKG.expLines_codeCombID,
1791 p_chart_of_accounts_id IN AP_WEB_DB_AP_INT_PKG.glsob_chartOfAccountsID) IS
1792 ----------------------------------------------------------------------
1793 l_debug_info VARCHAR2(1000);
1794
1795 l_new_segments AP_OIE_KFF_SEGMENTS_T;
1796
1797 BEGIN
1798
1799 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start HandleInvalidDistCCID');
1800
1801 if (p_report_distribution_id is null) then
1802 if ((p_payment_due = C_CompanyPay AND p_exp_type_parameter_id = p_personalParameterId) or
1803 (p_CategoryCode = C_ROUNDING))then
1804 -- if dist does not exist then it adds dist and then updates
1805 -- ccid and segments based on p_exp_dist_ccid
1806 AP_WEB_DB_EXPDIST_PKG.updateAccountValues (
1807 p_report_header_id => p_report_header_id,
1808 p_report_line_id => p_ReportLineId,
1809 p_report_distribution_id => p_report_distribution_id,
1810 p_ccid => p_exp_dist_ccid);
1811 else
1812 -- When error occurs building the ccid we should update the
1813 -- dist table with the correct segments which caused the issue
1814
1815 -----------------------------------------------------
1816 l_debug_info := 'Assign values to l_new_segments';
1817 -----------------------------------------------------
1818 l_new_segments := AP_OIE_KFF_SEGMENTS_T('');
1819 l_new_segments.extend(p_default_emp_segments.count);
1820 FOR i IN 1..p_default_emp_segments.count LOOP
1821 l_new_segments(i) := nvl(p_dist_new_segments(i),p_default_emp_segments(i));
1822 END LOOP;
1823
1824 -----------------------------------------------------
1825 l_debug_info := 'Add Dist for Line';
1826 -----------------------------------------------------
1827 AP_WEB_DB_EXPDIST_PKG.AddDistributionLine(
1828 p_segments => l_new_segments,
1829 p_report_line_id => p_ReportLineId,
1830 p_chart_of_accounts_id => p_chart_of_accounts_id);
1831 end if;
1832 end if; -- (p_report_distribution_id is null)
1833
1834 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end HandleInvalidDistCCID');
1835
1836 EXCEPTION
1837 WHEN OTHERS THEN
1838 IF (SQLCODE <> -20001) THEN
1839 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
1840 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1841 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'HandleInvalidDistCCID');
1842 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
1843 END IF;
1844 APP_EXCEPTION.RAISE_EXCEPTION;
1845 END HandleInvalidDistCCID;
1846
1847
1848 ----------------------------------------------------------------------
1849 PROCEDURE DoAPValidation(p_item_type IN VARCHAR2,
1850 p_item_key IN VARCHAR2,
1851 p_report_header_id IN AP_EXPENSE_REPORT_HEADERS.report_header_id%TYPE) IS
1852 ----------------------------------------------------------------------
1853 l_sys_apply_advances_default AP_WEB_DB_AP_INT_PKG.apSetUp_applyAdvDefault;
1854 l_sys_allow_awt_flag AP_WEB_DB_AP_INT_PKG.apSetUp_allowAwtFlag;
1855 l_sys_default_xrate_type AP_WEB_DB_AP_INT_PKG.apSetUp_defaultExchRateType;
1856 l_sys_make_rate_mandatory AP_WEB_DB_AP_INT_PKG.apSetUp_makeMandatoryFlag;
1857 l_chart_of_accounts_id AP_WEB_DB_AP_INT_PKG.glsob_chartOfAccountsID;
1858 l_default_currency_code AP_WEB_DB_EXPRPT_PKG.expHdr_defaultCurrCode;
1859 l_week_end_date AP_WEB_DB_EXPRPT_PKG.expHdr_weekEndDate;
1860 l_exp_check_address_flag AP_WEB_DB_HR_INT_PKG.empCurrent_checkAddrFlag;
1861 l_ven_allow_awt_flag AP_WEB_DB_AP_INT_PKG.vendors_allowAWTFlag;
1862 l_ven_awt_group_id AP_WEB_DB_AP_INT_PKG.vendors_awtGroupID;
1863 l_default_emp_ccid AP_WEB_DB_HR_INT_PKG.empCurrent_defaultCodeCombID;
1864 l_default_emp_segments AP_OIE_KFF_SEGMENTS_T;
1865 l_exp_dist_ccid AP_WEB_DB_EXPLINE_PKG.expLines_codeCombID;
1866 l_id_flex_structure_name fnd_id_flex_structures_vl.id_flex_structure_name%TYPE;
1867
1868 l_employee_ccid AP_WEB_DB_EXPRPT_PKG.expHdr_employeeCCID;
1869 l_employee_id AP_WEB_DB_EXPRPT_PKG.expHdr_employeeID;
1870 l_personalParameterId AP_WEB_DB_EXPTEMPLATE_PKG.expTempl_paramID;
1871 l_category AP_WEB_DB_CCARD_PKG.ccTrxn_category;
1872 l_default_exchange_rate AP_WEB_DB_EXPRPT_PKG.expHdr_defaultExchRate;
1873 l_base_currency_code AP_WEB_DB_AP_INT_PKG.apSetUp_baseCurrencyCode;
1874 l_sys_base_currency_code AP_WEB_DB_AP_INT_PKG.apSetUp_baseCurrencyCode;
1875 exchange_rate_exception EXCEPTION;
1876 l_available_prepays NUMBER;
1877 l_payment_due VARCHAR2(10) := C_IndividualPay;
1878
1879 l_debug_info VARCHAR2(1000);
1880
1881 V_PADefaultDistCCID AP_WEB_DB_EXPLINE_PKG.expLines_codeCombID;
1882 V_ConcatSegs VARCHAR2(2000);
1883 V_ConcatIDs VARCHAR2(2000);
1884 V_ConcatDescrs VARCHAR2(300);
1885 V_ErrMsg VARCHAR2(2000);--2048712
1886 V_ProcedureReturnCode VARCHAR2(2000);
1887 V_ProcedureBillableFlag VARCHAR2(200);
1888 V_PATCMsgType VARCHAR2(10); -- Value not used in 11.0, but used in 11.5+
1889
1890 V_DefaultExchangeRateType AP_WEB_DB_AP_INT_PKG.apSetUp_defaultExchRateType; -- For PATC: Exchange rate type in AP
1891 V_BaseCurrencyCode AP_WEB_DB_AP_INT_PKG.apSetUp_baseCurrencyCode; -- For PATC: Functional currency
1892 V_ReimbCurrencyCode VARCHAR2(15);
1893 V_DefaultExchangeRate NUMBER; -- For PATC: Exchange rate for func->reimb
1894 V_AcctRawCost NUMBER; -- For PATC: Receipt amount in functional currency
1895 V_WeekEndDate DATE;
1896 C_WF_Version NUMBER := 0;
1897 l_SysInfoRec AP_WEB_DB_AP_INT_PKG.APSysInfoRec;
1898
1899 l_error_message VARCHAR2(2000);
1900
1901 V_UserID NUMBER;
1902 V_UserName VARCHAR2(30);
1903 V_VendorID AP_WEB_DB_AP_INT_PKG.vendors_vendorID;
1904 V_IsSessionProjectEnabled VARCHAR2(1);
1905
1906 V_EmployeeID AP_WEB_DB_EXPRPT_PKG.expHdr_employeeID;
1907 l_cost_center AP_WEB_DB_EXPRPT_PKG.expHdr_flexConcat;
1908 V_HeaderAttributeCategory AP_WEB_DB_EXPRPT_PKG.expHdr_attrCategory;
1909 V_HeaderAttribute1 AP_WEB_DB_EXPRPT_PKG.expHdr_attr1;
1910 V_HeaderAttribute2 AP_WEB_DB_EXPRPT_PKG.expHdr_attr2;
1911 V_HeaderAttribute3 AP_WEB_DB_EXPRPT_PKG.expHdr_attr3;
1912 V_HeaderAttribute4 AP_WEB_DB_EXPRPT_PKG.expHdr_attr4;
1913 V_HeaderAttribute5 AP_WEB_DB_EXPRPT_PKG.expHdr_attr5;
1914 V_HeaderAttribute6 AP_WEB_DB_EXPRPT_PKG.expHdr_attr6;
1915 V_HeaderAttribute7 AP_WEB_DB_EXPRPT_PKG.expHdr_attr7;
1916 V_HeaderAttribute8 AP_WEB_DB_EXPRPT_PKG.expHdr_attr8;
1917 V_HeaderAttribute9 AP_WEB_DB_EXPRPT_PKG.expHdr_attr9;
1918 V_HeaderAttribute10 AP_WEB_DB_EXPRPT_PKG.expHdr_attr10;
1919 V_HeaderAttribute11 AP_WEB_DB_EXPRPT_PKG.expHdr_attr11;
1920 V_HeaderAttribute12 AP_WEB_DB_EXPRPT_PKG.expHdr_attr12;
1921 V_HeaderAttribute13 AP_WEB_DB_EXPRPT_PKG.expHdr_attr13;
1922 V_HeaderAttribute14 AP_WEB_DB_EXPRPT_PKG.expHdr_attr14;
1923 V_HeaderAttribute15 AP_WEB_DB_EXPRPT_PKG.expHdr_attr15;
1924
1925 ExpenseReportLinesCursor AP_WEB_DB_EXPLINE_PKG.XpenseLineAcctCursor;
1926 l_dist_line_number AP_WEB_DB_EXPLINE_PKG.expLines_distLineNum;
1927 l_report_distribution_id AP_WEB_DB_EXPDIST_PKG.expDist_REPORT_DISTRIBUTION_ID;
1928 V_StartExpenseDate AP_WEB_DB_EXPLINE_PKG.expLines_startExpDate;
1929 V_Amount AP_WEB_DB_EXPLINE_PKG.expLines_amount;
1930 V_ExpenseType AP_EXPENSE_REPORT_PARAMS.web_friendly_prompt%TYPE;
1931 V_CreditCardTrxID AP_WEB_DB_EXPLINE_PKG.expLines_crdCardTrxID;
1932 V_ProjectID AP_WEB_DB_EXPLINE_PKG.expLines_projID;
1933 V_TaskID AP_WEB_DB_EXPLINE_PKG.expLines_taskID;
1934 -- Grants Integration
1935 V_AwardID GMS_OIE_INT_PKG.gms_awardId;
1936 V_AwardSetID NUMBER := NULL;
1937 V_ExpenditureItemDate AP_WEB_DB_EXPLINE_PKG.expLines_expendItemDate;
1938 V_ExpenditureType AP_WEB_DB_EXPLINE_PKG.expLines_expendType;
1939 V_PAQuantity AP_WEB_DB_EXPLINE_PKG.expLines_paQuantity;
1940 V_ExpenditureOrganizationID AP_WEB_DB_EXPLINE_PKG.expLines_expOrgID;
1941 l_exp_type_parameter_id AP_WEB_DB_EXPLINE_PKG.expLines_webParamID;
1942 V_AdjustmentReason AP_WEB_DB_EXPLINE_PKG.expLines_adjReason;
1943 V_CategoryCode AP_WEB_DB_EXPLINE_PKG.expLines_categorycode;
1944 V_FlexConcactenated AP_EXPENSE_REPORT_PARAMS.flex_concactenated%TYPE;
1945 V_LineAttributeCategory AP_WEB_DB_EXPLINE_PKG.expLines_attrCategory;
1946 V_LineAttribute1 AP_WEB_DB_EXPLINE_PKG.expLines_attr1;
1947 V_LineAttribute2 AP_WEB_DB_EXPLINE_PKG.expLines_attr2;
1948 V_LineAttribute3 AP_WEB_DB_EXPLINE_PKG.expLines_attr3;
1949 V_LineAttribute4 AP_WEB_DB_EXPLINE_PKG.expLines_attr4;
1950 V_LineAttribute5 AP_WEB_DB_EXPLINE_PKG.expLines_attr5;
1951 V_LineAttribute6 AP_WEB_DB_EXPLINE_PKG.expLines_attr6;
1952 V_LineAttribute7 AP_WEB_DB_EXPLINE_PKG.expLines_attr7;
1953 V_LineAttribute8 AP_WEB_DB_EXPLINE_PKG.expLines_attr8;
1954 V_LineAttribute9 AP_WEB_DB_EXPLINE_PKG.expLines_attr9;
1955 V_LineAttribute10 AP_WEB_DB_EXPLINE_PKG.expLines_attr10;
1956 V_LineAttribute11 AP_WEB_DB_EXPLINE_PKG.expLines_attr11;
1957 V_LineAttribute12 AP_WEB_DB_EXPLINE_PKG.expLines_attr12;
1958 V_LineAttribute13 AP_WEB_DB_EXPLINE_PKG.expLines_attr13;
1959 V_LineAttribute14 AP_WEB_DB_EXPLINE_PKG.expLines_attr14;
1960 V_LineAttribute15 AP_WEB_DB_EXPLINE_PKG.expLines_attr15;
1961 V_LineFlexConcat AP_WEB_DB_EXPLINE_PKG.expLines_LineFlexConcat;
1962 l_line_cost_center AP_WEB_DB_EXPLINE_PKG.expLines_LineFlexConcat;
1963 V_APValidationError AP_WEB_DB_EXPLINE_PKG.expLines_APValidationError;
1964 V_ReportLineId AP_WEB_DB_EXPLINE_PKG.expLines_report_line_id;
1965
1966 l_concatenated_segments varchar2(2000);
1967
1968 l_header_error_message VARCHAR2(2000);
1969 l_return_error_message VARCHAR2(2000);
1970 l_return_status VARCHAR2(30);
1971 l_fatal_error_occurred BOOLEAN := false;
1972 l_header_error_occurred BOOLEAN := false;
1973 l_line_error_occurred BOOLEAN := false;
1974 l_other_error_occurred BOOLEAN := false;
1975 l_add_to_line_error BOOLEAN := false;
1976 l_line_error_message VARCHAR2(2000);
1977 l_other_error_message VARCHAR2(2000);
1978 l_is_projects_report BOOLEAN := false;
1979 l_line_num NUMBER := 0;
1980 l_cash_line_num NUMBER := 0;
1981 l_ccard_line_num NUMBER := 0;
1982 l_yes VARCHAR2(80);
1983 l_no VARCHAR2(80);
1984 l_rounding_error_ccid AP_WEB_DB_EXPLINE_PKG.expLines_codeCombID;
1985 l_card_program_id NUMBER := 0;
1986
1987 l_existing_segments AP_OIE_KFF_SEGMENTS_T;
1988 l_new_segments AP_OIE_KFF_SEGMENTS_T;
1989 l_dist_new_segments AP_OIE_KFF_SEGMENTS_T;
1990
1991 l_transaction_date ap_credit_card_trxns_all.transaction_date%type;
1992
1993 BEGIN
1994
1995 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start DoAPValidation');
1996
1997 ---------------------------------------------------
1998 l_debug_info := 'Clear out potentially rejected/returned status';
1999 ---------------------------------------------------
2000 UPDATE ap_expense_report_headers erh
2001 SET workflow_approved_flag = '',
2002 source = 'NonValidatedWebExpense'
2003 WHERE report_header_id = p_report_header_id;
2004
2005 --------------------------------------------------------------------
2006 l_debug_info := 'Retrieve values from system parameters, employees';
2007 --------------------------------------------------------------------
2008 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetAccountingInfo(
2009 p_report_header_id,
2010 l_sys_apply_advances_default,
2011 l_sys_allow_awt_flag,
2012 l_sys_default_xrate_type,
2013 l_sys_make_rate_mandatory,
2014 l_exp_check_address_flag,
2015 l_default_currency_code,
2016 l_week_end_date,
2017 l_cost_center,
2018 l_employee_id)) THEN
2019 NULL;
2020 END IF; /* GetAccountingInfo */
2021
2022 ------------------------------------------------------------
2023 l_debug_info := 'Get Emp Acctg Info';
2024 ------------------------------------------------------------
2025 begin
2026 AP_WEB_ACCTG_PKG.BuildAccount(
2027 p_report_header_id => null,
2028 p_report_line_id => null,
2029 p_employee_id => l_employee_id,
2030 p_cost_center => l_cost_center,
2031 p_line_cost_center => null,
2032 p_exp_type_parameter_id => null,
2033 p_segments => null,
2034 p_ccid => null,
2035 p_build_mode => AP_WEB_ACCTG_PKG.C_DEFAULT_VALIDATE,
2036 p_new_segments => l_default_emp_segments,
2037 p_new_ccid => l_employee_ccid,
2038 p_return_error_message => l_header_error_message);
2039
2040 -----------------------------------------------------
2041 l_debug_info := 'Get the Employee Chart of Accounts ID';
2042 -----------------------------------------------------
2043 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetChartOfAccountsID(
2044 p_employee_id => l_employee_id,
2045 p_chart_of_accounts_id => l_chart_of_accounts_id)) THEN
2046 NULL;
2047 END IF;
2048
2049 AP_WEB_ACCTG_PKG.GetConcatenatedSegments(
2050 p_chart_of_accounts_id => l_chart_of_accounts_id,
2051 p_segments => l_default_emp_segments,
2052 p_concatenated_segments => l_concatenated_segments);
2053
2054 exception
2055 when AP_WEB_OA_MAINFLOW_PKG.G_EXC_ERROR then
2056 l_header_error_message := FND_MESSAGE.Get;
2057 end;
2058
2059 if (l_header_error_message is not null) then
2060
2061 l_fatal_error_occurred := true;
2062 AddToHeaderErrors(p_item_type,
2063 p_item_key,
2064 l_concatenated_segments||': '||l_header_error_message);
2065 return;
2066 end if;
2067
2068 ------------------------------------------------------------
2069 l_debug_info := 'begin preparation for Project Account Generation';
2070 ------------------------------------------------------------
2071
2072 -- Get version of Workflow
2073 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
2074
2075 -- Determine whether project enabled
2076 l_debug_info := 'Determine whether project enabled';
2077 V_UserID := WF_ENGINE.GetItemAttrNumber(p_item_type,
2078 p_item_key,
2079 'EMPLOYEE_ID');
2080
2081 ------------------------------------------------------------
2082 l_debug_info := 'Determine whether session is project enabled';
2083 ------------------------------------------------------------
2084 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_11_0_3Version) THEN
2085 V_IsSessionProjectEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
2086 p_item_key,
2087 'EMPLOYEE_PROJECT_ENABLED');
2088 ELSE
2089 -- In previous versions we called
2090 -- AP_WEB_PROJECT_PKG.IsSessionProjectEnabled, but that would not work
2091 -- without having ValidateSession called. So, for older versions we
2092 -- will assume that the session is project enabled. Since the receipts
2093 -- will not have any project information, the patc call will not be done.
2094 V_IsSessionProjectEnabled := 'Y';
2095 END IF; /* checking wf version */
2096
2097 ------------------------------------------------------------
2098 l_debug_info := 'end preparation for Project Account Generation';
2099 ------------------------------------------------------------
2100
2101 ------------------------------------------------------------------------
2102 l_debug_info := 'calling AP_WEB_DB_EXPLINE_PKG.GetExpDistAcctCursor';
2103 ------------------------------------------------------------------------
2104 IF (AP_WEB_DB_EXPLINE_PKG.GetExpDistAcctCursor(p_report_header_id,
2105 ExpenseReportLinesCursor)) THEN
2106
2107 ---------------------------------------------------------
2108 l_debug_info := 'Retrieve Payment Due From System Option';
2109 ---------------------------------------------------------
2110 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
2111
2112 IF (l_payment_due = C_CompanyPay) then
2113 ------------------------------------------------------------------------
2114 l_debug_info := 'calling AP_WEB_DB_EXPTEMPLATE_PKG.GetPersonalParamID';
2115 ------------------------------------------------------------------------
2116 IF (NOT AP_WEB_DB_EXPTEMPLATE_PKG.GetPersonalParamID(l_personalParameterId)) THEN
2117 FND_MESSAGE.SET_NAME('SQLAP','OIE_NO_PERSONAL_EXP_TYPE');
2118 AddToHeaderErrors(p_item_type,
2119 p_item_key,
2120 FND_MESSAGE.GET);
2121 l_header_error_occurred := true;
2122 END IF; /* GetPersonalParamID */
2123
2124 END IF; /* C_CompanyPay */
2125
2126 ------------------------------------------------------------------------
2127 l_debug_info := 'Calling AP_WEB_DB_AP_INT_PKG.GetRoundingErrorCCID';
2128 ------------------------------------------------------------------------
2129 IF (NOT AP_WEB_DB_AP_INT_PKG.GetRoundingErrorCCID(l_rounding_error_ccid)) THEN
2130 l_rounding_error_ccid := NULL;
2131 END IF; /* GetRoundingErrorCCID */
2132
2133 LOOP
2134 FETCH ExpenseReportLinesCursor INTO
2135 l_dist_line_number,
2136 l_report_distribution_id,
2137 V_StartExpenseDate,
2138 V_Amount,
2139 V_ExpenseType,
2140 V_CreditCardTrxID,
2141 V_ProjectID,
2142 V_TaskID,
2143 V_AwardID,
2144 V_ExpenditureItemDate,
2145 V_ExpenditureType,
2146 V_PAQuantity,
2147 V_ExpenditureOrganizationID,
2148 l_exp_type_parameter_id,
2149 V_AdjustmentReason,
2150 V_FlexConcactenated,
2151 V_CategoryCode,
2152 V_LineAttributeCategory,
2153 V_LineAttribute1,
2154 V_LineAttribute2,
2155 V_LineAttribute3,
2156 V_LineAttribute4,
2157 V_LineAttribute5,
2158 V_LineAttribute6,
2159 V_LineAttribute7,
2160 V_LineAttribute8,
2161 V_LineAttribute9,
2162 V_LineAttribute10,
2163 V_LineAttribute11,
2164 V_LineAttribute12,
2165 V_LineAttribute13,
2166 V_LineAttribute14,
2167 V_LineAttribute15,
2168 l_line_cost_center,
2169 V_APValidationError,
2170 V_ReportLineId;
2171 EXIT WHEN ExpenseReportLinesCursor%NOTFOUND;
2172
2173 ------------------------------------------------------------------------
2174 l_debug_info := 'reset l_line_error_message';
2175 ------------------------------------------------------------------------
2176 l_line_error_message := '';
2177 l_add_to_line_error := false;
2178
2179 ------------------------------------------------------------------------
2180 l_debug_info := 'set l_ccard_line_num or l_cash_line_num';
2181 ------------------------------------------------------------------------
2182 if (V_CreditCardTrxID is not null) then
2183 l_ccard_line_num := l_ccard_line_num + 1;
2184 l_line_num := l_ccard_line_num;
2185 else
2186 l_cash_line_num := l_cash_line_num + 1;
2187 l_line_num := l_cash_line_num;
2188 end if;
2189
2190 ------------------------------------------------------------------------
2191 l_debug_info := 'begin Project Account Generation';
2192 ------------------------------------------------------------------------
2193 IF (V_IsSessionProjectEnabled = 'Y' AND V_ProjectID IS NOT NULL) THEN
2194
2195 ------------------------------------------------------------------------
2196 l_debug_info := 'set l_is_projects_report := true';
2197 ------------------------------------------------------------------------
2198 l_is_projects_report := true;
2199
2200 ------------------------------------------------------------------------
2201 l_debug_info := 'AP_WEB_ACCTG_PKG.BuildDistProjectAccount';
2202 ------------------------------------------------------------------------
2203 AP_WEB_ACCTG_PKG.BuildDistProjectAccount(
2204 p_report_header_id => p_report_header_id,
2205 p_report_line_id => V_ReportLineId,
2206 p_report_distribution_id => l_report_distribution_id,
2207 p_exp_type_parameter_id => l_exp_type_parameter_id,
2208 p_new_segments => l_dist_new_segments,
2209 p_new_ccid => l_exp_dist_ccid,
2210 p_return_error_message => l_return_error_message,
2211 p_return_status => l_return_status);
2212
2213 if (l_return_status like '%ERROR%') then
2214 l_line_error_message := l_line_error_message || l_return_error_message || '<br>';
2215 l_add_to_line_error := true;
2216 end if;
2217
2218 --------------------------------------------------------------
2219 l_debug_info:='Credit the Personal lines with a different ccid';
2220 --------------------------------------------------------------
2221 IF (l_payment_due = C_CompanyPay AND l_exp_type_parameter_id = l_personalParameterId) THEN
2222
2223 SELECT card_program_id, transaction_date
2224 INTO l_card_program_id, l_transaction_date
2225 FROM ap_credit_card_trxns
2226 WHERE trx_id = V_CreditCardTrxID;
2227
2228 IF (NOT AP_WEB_DB_AP_INT_PKG.GetExpenseClearingCCID(p_ccid => l_exp_dist_ccid,
2229 p_card_program_id => l_card_program_id,
2230 p_employee_id => l_employee_id,
2231 p_as_of_date => l_transaction_date)) THEN
2232 l_exp_dist_ccid := NULL;
2233 END IF; /* GetExpenseClearingCCID */
2234
2235 --------------------------------------------------------------
2236 l_debug_info:='Personal Expense Clearing CCID is NULL';
2237 --------------------------------------------------------------
2238 IF (l_exp_dist_ccid IS NULL) THEN
2239 l_line_error_message := l_line_error_message || 'Personal Expense Clearing CCID is NULL' || '<br>';
2240 l_add_to_line_error := true;
2241 END IF; /* l_exp_dist_ccid IS NULL */
2242
2243 ELSIF (V_CategoryCode = C_ROUNDING) THEN
2244
2245 --------------------------------------------
2246 l_debug_info := 'Rounding';
2247 --------------------------------------------
2248 l_exp_dist_ccid := l_rounding_error_ccid;
2249 IF (l_rounding_error_ccid IS NULL) THEN
2250 --------------------------------------------
2251 l_debug_info := 'Rounding Error CCID is NULL';
2252 --------------------------------------------
2253 FND_MESSAGE.SET_NAME('SQLAP','OIE_NO_ROUNDING_CCID');
2254 l_other_error_message := FND_MESSAGE.GET;
2255 AddToOtherErrors(p_item_type,
2256 p_item_key,
2257 l_concatenated_segments||': '||l_other_error_message);
2258 l_other_error_occurred := true;
2259 END IF; /* l_rounding_error_ccid IS NULL */
2260
2261 ELSE
2262
2263 -- set the code combination for the line
2264 if (l_exp_dist_ccid is null OR l_exp_dist_ccid = -1) then
2265 l_line_error_message := l_line_error_message;
2266 l_add_to_line_error := true;
2267 end if; /* l_exp_dist_ccid is null */
2268
2269 END IF; /* l_payment_due = C_CompanyPay AND l_exp_type_parameter_id = l_personalParameterId */
2270
2271 if (l_exp_dist_ccid is null OR
2272 l_exp_dist_ccid = -1) then
2273
2274 HandleInvalidDistCCID(p_report_header_id,
2275 l_report_distribution_id,
2276 l_payment_due,
2277 l_exp_type_parameter_id,
2278 l_personalParameterId,
2279 V_CategoryCode,
2280 l_default_emp_segments,
2281 l_dist_new_segments,
2282 V_ReportLineId,
2283 l_exp_dist_ccid,
2284 l_chart_of_accounts_id);
2285 else
2286 /* Also update the segment values in the dist table to ensure the ccid
2287 and the segment values are in sync. */
2288 --------------------------------------------------------------
2289 l_debug_info:='Synch Account Segments with CCID';
2290 -- updateAccountValues calls AddDistributionLine if dist does not
2291 -- exist and then updates the ccid and segments based on l_exp_dist_ccid
2292 --------------------------------------------------------------
2293 AP_WEB_DB_EXPDIST_PKG.updateAccountValues (
2294 p_report_header_id => p_report_header_id,
2295 p_report_line_id => V_ReportLineId,
2296 p_report_distribution_id => l_report_distribution_id,
2297 p_ccid => l_exp_dist_ccid);
2298
2299 end if; /* l_exp_dist_ccid is null */
2300
2301 ------------------------------------------------------------------------
2302 l_debug_info := 'end Project Account Generation';
2303 ------------------------------------------------------------------------
2304
2305 ELSE
2306 ------------------------------------------------------------------------
2307 l_debug_info := 'begin Non-Project Account Generation';
2308 ------------------------------------------------------------------------
2309 --------------------------------------------------------------
2310 l_debug_info:='Credit the Personal lines with a different ccid';
2311 --------------------------------------------------------------
2312 IF (l_payment_due = C_CompanyPay AND l_exp_type_parameter_id = l_personalParameterId) THEN
2313
2314 SELECT card_program_id, transaction_date
2315 INTO l_card_program_id, l_transaction_Date
2316 FROM ap_credit_card_trxns
2317 WHERE trx_id = V_CreditCardTrxID;
2318
2319 IF (NOT AP_WEB_DB_AP_INT_PKG.GetExpenseClearingCCID(p_ccid => l_exp_dist_ccid,
2320 p_card_program_id => l_card_program_id,
2321 p_employee_id => l_employee_id,
2322 p_as_of_date => l_transaction_date)) THEN
2323 l_exp_dist_ccid := NULL;
2324 END IF; /* GetExpenseClearingCCID */
2325
2326 --------------------------------------------------------------
2327 l_debug_info:='Personal Expense Clearing CCID is NULL';
2328 --------------------------------------------------------------
2329 IF (l_exp_dist_ccid IS NULL) THEN
2330 l_line_error_message := l_line_error_message || 'Personal Expense Clearing CCID is NULL' || '<br>';
2331 l_add_to_line_error := true;
2332 END IF; /* l_exp_dist_ccid IS NULL */
2333
2334 ELSIF (V_CategoryCode = 'ROUNDING' ) THEN
2335 l_exp_dist_ccid := l_rounding_error_ccid;
2336 --------------------------------------------
2337 l_debug_info := 'Rounding Error CCID is NULL';
2338 --------------------------------------------
2339 IF ( l_rounding_error_ccid IS NULL) THEN
2340 FND_MESSAGE.SET_NAME('SQLAP','OIE_NO_ROUNDING_CCID');
2341 l_other_error_message := FND_MESSAGE.GET;
2342 AddToOtherErrors(p_item_type,
2343 p_item_key,
2344 l_concatenated_segments||': '||l_other_error_message);
2345 l_other_error_occurred := true;
2346
2347 END IF; /*l_rounding_error_ccid IS NULL*/
2348
2349 ELSE
2350 -- Removed code for 'LLA Enabled with Online Validation';
2351 -- i.e, Removed call to AP_WEB_DB_EXPDIST_PKG.UpdateDistCCID
2352 -- as there is no change in l_exp_dist_ccid
2353
2354 IF (l_report_distribution_id is not null) THEN -- Distribution Exist
2355
2356 IF (NOT AP_WEB_DB_EXPDIST_PKG.foundCCID(l_report_distribution_id, l_exp_dist_ccid)) THEN
2357
2358 --------------------------------------------------------------
2359 l_debug_info:='LLA Enabled without Online Validation';
2360 --------------------------------------------------------------
2361 --------------------------------------------------------------
2362 l_debug_info:='Get Distribution Segments';
2363 --------------------------------------------------------------
2364 AP_WEB_ACCTG_PKG.GetDistributionSegments(
2365 p_chart_of_accounts_id => l_chart_of_accounts_id,
2366 p_report_distribution_id => l_report_distribution_id,
2367 p_segments => l_existing_segments);
2368
2369 --------------------------------------------------------------
2370 l_debug_info:='Build Account';
2371 --------------------------------------------------------------
2372 AP_WEB_ACCTG_PKG.BuildAccount(
2373 p_report_header_id => p_report_header_id,
2374 p_report_line_id => V_ReportLineId,
2375 p_employee_id => l_employee_id,
2376 p_cost_center => l_cost_center,
2377 p_line_cost_center => l_line_cost_center,
2378 p_exp_type_parameter_id => l_exp_type_parameter_id,
2379 p_segments => l_existing_segments,
2380 p_ccid => null,
2381 p_build_mode => AP_WEB_ACCTG_PKG.C_VALIDATE,
2382 p_new_segments => l_dist_new_segments,
2383 p_new_ccid => l_exp_dist_ccid,
2384 p_return_error_message => l_return_error_message);
2385
2386 if (l_return_error_message is not null) then
2387 l_line_error_message := l_line_error_message || l_return_error_message || ' ';
2388 l_add_to_line_error := true;
2389 end if;
2390
2391 END IF; -- (Not AP_WEB_DB_EXPDIST_PKG.foundCCID) 'LLA Enabled without Online Validation';
2392
2393 ELSE -- else of Distribution Exist
2394
2395 --------------------------------------------------------------
2396 l_debug_info:='LLA Disabled';
2397 --------------------------------------------------------------
2398 l_existing_segments := null;
2399 l_new_segments := null;
2400
2401 --------------------------------------------------------------
2402 l_debug_info:='Build Account';
2403 --------------------------------------------------------------
2404 AP_WEB_ACCTG_PKG.BuildAccount(
2405 p_report_header_id => p_report_header_id,
2406 p_report_line_id => V_ReportLineId,
2407 p_employee_id => l_employee_id,
2408 p_cost_center => l_cost_center,
2409 p_line_cost_center => l_line_cost_center,
2410 p_exp_type_parameter_id => l_exp_type_parameter_id,
2411 p_segments => l_existing_segments,
2412 p_ccid => null,
2413 p_build_mode => AP_WEB_ACCTG_PKG.C_DEFAULT_VALIDATE,
2414 p_new_segments => l_dist_new_segments,
2415 p_new_ccid => l_exp_dist_ccid,
2416 p_return_error_message => l_return_error_message);
2417
2418 if (l_return_error_message is not null) then
2419 l_line_error_message := l_line_error_message || l_return_error_message || ' ';
2420 l_add_to_line_error := true;
2421 end if;
2422
2423 END IF; /* foundDistributions */
2424
2425 END IF; /* l_payment_due = C_CompanyPay AND l_exp_type_parameter_id = l_personalParameterId */
2426
2427
2428 if (l_exp_dist_ccid is null OR
2429 l_exp_dist_ccid = -1) then
2430
2431 HandleInvalidDistCCID(p_report_header_id,
2432 l_report_distribution_id,
2433 l_payment_due,
2434 l_exp_type_parameter_id,
2435 l_personalParameterId,
2436 V_CategoryCode,
2437 l_default_emp_segments,
2438 l_dist_new_segments,
2439 V_ReportLineId,
2440 l_exp_dist_ccid,
2441 l_chart_of_accounts_id);
2442
2443 l_line_error_message := l_line_error_message;
2444 l_add_to_line_error := true;
2445
2446 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_OIEJ_Version) THEN
2447 WF_ENGINE.SetItemAttrText(p_item_type,
2448 p_item_key,
2449 'EXP_ALLOCATION_ERRORS',
2450 'Y');
2451 END IF;
2452
2453 else
2454
2455 /* Also update the segment values in the dist table to ensure the ccid
2456 and the segment values are in sync. */
2457 --------------------------------------------------------------
2458 l_debug_info:='Synch Account Segments with CCID';
2459 -- updateAccountValues calls AddDistributionLine if dist does not
2460 -- exist and then updates the ccid and segments based on l_exp_dist_ccid
2461 --------------------------------------------------------------
2462 AP_WEB_DB_EXPDIST_PKG.updateAccountValues (
2463 p_report_header_id => p_report_header_id,
2464 p_report_line_id => V_ReportLineId,
2465 p_report_distribution_id => l_report_distribution_id,
2466 p_ccid => l_exp_dist_ccid);
2467
2468 end if; /* l_exp_dist_ccid is null */
2469
2470 ------------------------------------------------------------------------
2471 l_debug_info := 'end Non-Project Account Generation';
2472 ------------------------------------------------------------------------
2473
2474 END IF; /* end Project and non-Project Account Generation */
2475
2476 ------------------------------------------------------------------------
2477 l_debug_info := 'check to see if line error occurred';
2478 ------------------------------------------------------------------------
2479 if (l_add_to_line_error) then
2480
2481 AP_WEB_DB_EXPLINE_PKG.UpdateAPValidationError(
2482 p_report_header_id => p_report_header_id,
2483 p_dist_line_number => l_dist_line_number,
2484 p_ap_validation_error => l_line_error_message);
2485
2486 l_line_error_occurred := true;
2487
2488 end if;
2489
2490 END LOOP; /* ExpenseReportLinesCursor */
2491
2492 END IF; /* GetExpDistAcctCursor */
2493
2494 if ExpenseReportLinesCursor%isopen then
2495 CLOSE ExpenseReportLinesCursor;
2496 end if;
2497
2498 ----------------------------------------------------------------
2499 l_debug_info := 'Set Is Projects Expense Report?';
2500 -----------------------------------------------------------------
2501 if (l_is_projects_report) then
2502
2503 SELECT fndl.meaning
2504 INTO l_yes
2505 FROM FND_LOOKUPS fndl
2506 WHERE fndl.LOOKUP_TYPE = C_YES_NO
2507 AND fndl.LOOKUP_CODE = C_Y;
2508
2509 WF_ENGINE.SetItemAttrText(p_item_type,
2510 p_item_key,
2511 'IS_PROJECTS_REPORT',
2512 l_yes);
2513 else
2514 SELECT fndl.meaning
2515 INTO l_no
2516 FROM FND_LOOKUPS fndl
2517 WHERE fndl.LOOKUP_TYPE = C_YES_NO
2518 AND fndl.LOOKUP_CODE = C_N;
2519
2520 WF_ENGINE.SetItemAttrText(p_item_type,
2521 p_item_key,
2522 'IS_PROJECTS_REPORT',
2523 l_no);
2524 end if; /* l_is_projects_report */
2525
2526 ------------------------------------------------
2527 l_debug_info := 'Retrieve function currency';
2528 ------------------------------------------------
2529 IF (NOT AP_WEB_DB_AP_INT_PKG.GetBaseCurrInfo(l_sys_base_currency_code)) THEN
2530 l_sys_base_currency_code := NULL;
2531 END IF; /* GetBaseCurrInfo */
2532
2533 ------------------------------------------------
2534 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;
2535 ------------------------------------------------
2536 IF (gl_currency_api.is_fixed_rate(l_sys_base_currency_code,
2537 l_default_currency_code,
2538 sysdate) = 'Y') THEN
2539
2540 IF (l_sys_base_currency_code <> l_default_currency_code) THEN --euro, bug 1289501
2541 l_sys_default_xrate_type := 'EMU FIXED';
2542 END IF; /* l_sys_base_currency_code <> l_default_currency_code */
2543
2544 END IF; /* is_fixed_rate */
2545
2546 IF (NOT AP_WEB_DB_AP_INT_PKG.GetBaseCurrInfo(l_base_currency_code)) THEN
2547 l_base_currency_code := null;
2548 END IF; /* GetBaseCurrInfo */
2549
2550 ----------------------------------------------
2551 l_debug_info := 'Check for invalid Rate Type';
2552 ----------------------------------------------
2553 IF ((l_sys_default_xrate_type = 'User') AND
2554 (l_sys_make_rate_mandatory = 'Y')) THEN
2555
2556 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetDefaultExchRateType(p_report_header_id, l_sys_default_xrate_type)) THEN
2557 NULL;
2558 END IF; /* SetDefaultExchRateType */
2559
2560 FND_MESSAGE.SET_NAME('SQLAP','AP_WEB_USER_EXCH_RATE_REQD');
2561 l_return_error_message := FND_MESSAGE.GET;
2562 AddToHeaderErrors(p_item_type,
2563 p_item_key,
2564 l_return_error_message);
2565 l_header_error_occurred := true;
2566
2567 ELSE
2568 --Bug 2974741: Replace sysdate with l_week_end_date to get correct rate.
2569 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');
2570 END IF; /* Check for invalid Rate Type */
2571
2572
2573 --------------------------------------------------------------------
2574 l_debug_info := 'Check to see if error occurred before proceeding';
2575 --------------------------------------------------------------------
2576 if (l_header_error_occurred OR l_line_error_occurred OR l_other_error_occurred) then
2577 Return;
2578 end if; /* l_header_error_occurred OR l_line_error_occurred */
2579
2580 --------------------------------------------------------------------
2581 l_debug_info := 'Calculate available prepayments for this employee';
2582 --------------------------------------------------------------------
2583 IF (NOT AP_WEB_DB_AP_INT_PKG.GetAvailablePrepayments(l_employee_id,
2584 l_default_currency_code,
2585 l_available_prepays)) THEN
2586 l_available_prepays := NULL;
2587 END IF; /* GetAvailablePrepayments */
2588
2589 ------------------------------------------------
2590 l_debug_info := 'Retrieve values from vendors';
2591 ------------------------------------------------
2592 IF (NOT AP_WEB_DB_AP_INT_PKG.GetVendorAWTSetupForExpRpt(p_report_header_id,
2593 l_ven_allow_awt_flag,
2594 l_ven_awt_group_id)) THEN
2595
2596 l_ven_allow_awt_flag := NULL;
2597 l_ven_awt_group_id := NULL;
2598
2599 END IF; /* GetVendorAWTSetupForExpRpt */
2600
2601 ---------------------------------------------------
2602 l_debug_info := 'Update ap_expense_report_headers';
2603 ---------------------------------------------------
2604 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetExpenseHeaderInfo(p_report_header_id,
2605 l_exp_check_address_flag,
2606 'WebExpense',
2607 '', -- clear out potentially-rejected/returned status
2608 l_sys_apply_advances_default,
2609 l_available_prepays,
2610 l_sys_allow_awt_flag,
2611 l_ven_allow_awt_flag,
2612 l_ven_awt_group_id,
2613 l_sys_default_xrate_type,
2614 l_week_end_date,
2615 l_default_exchange_rate,
2616 l_employee_ccid ) ) THEN
2617 NULL;
2618 END IF; /* SetExpenseHeaderInfo */
2619
2620 ---------------------------------------------------
2621 l_debug_info := 'Update ap_expense_report_lines';
2622 ---------------------------------------------------
2623 -- 7/24: insertion of receipt_required_flag is moved to the submit package.
2624 IF (NOT AP_WEB_DB_EXPLINE_PKG.SetAWTGroupIDAndJustif(p_report_header_id,
2625 l_sys_allow_awt_flag,
2626 l_ven_allow_awt_flag,
2627 l_ven_awt_group_id)) THEN
2628 NULL;
2629 END IF; /* SetAWTGroupIDAndJustif */
2630
2631 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end DoAPValidation');
2632
2633 EXCEPTION
2634 WHEN OTHERS THEN
2635 IF (SQLCODE <> -20001) THEN
2636 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
2637 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
2638 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'DoAPValidation');
2639 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
2640 END IF;
2641 APP_EXCEPTION.RAISE_EXCEPTION;
2642 END DoAPValidation;
2643
2644 -------------------------------------
2645 PROCEDURE OpenExp(p1 varchar2,
2646 p2 varchar2,
2647 p11 varchar2) IS
2648 -------------------------------------
2649 l_param varchar2(240);
2650 c_rowid varchar2(18);
2651 l_session_id number;
2652 l_icx_application_id AK_FLOW_REGION_RELATIONS.flow_application_id%TYPE := AP_WEB_INFRASTRUCTURE_PKG.GetICXApplicationId;
2653 l_url ICX_PARAMETERS.HOME_URL%TYPE := null;
2654
2655 BEGIN
2656
2657 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start OpenExp');
2658
2659 IF AP_WEB_INFRASTRUCTURE_PKG.ValidateSession(NULL, false, false) THEN
2660
2661 l_session_id := icx_sec.getID(icx_sec.PV_SESSION_ID);
2662 AP_WEB_INFRASTRUCTURE_PKG.ICXSetOrgContext(l_session_id, p11);
2663
2664 -- The following information needs to be set up through ON forms, on particular
2665 -- Page rlations.
2666
2667 IF (NOT AP_WEB_DB_UI_SETUP_PKG.GetAKPageRowID('ICX_AP_EXP_RPT_NEW_D',
2668 'ICX_AP_EXP_RPT_D',
2669 'ICX_AP_EXP_LINES_D',
2670 'ICX_INQUIRIES',
2671 l_icx_application_id,
2672 c_rowid)) THEN
2673 NULL;
2674 END IF;
2675
2676 l_param := icx_on_utilities.buildOracleONstring
2677 (p_rowid => c_rowid,
2678 p_primary_key => 'ICX_AP_EXP_RPT_PK',
2679 p1 => icx_call.decrypt(p1),
2680 p2 => icx_call.decrypt(p2));
2681
2682
2683 IF (l_session_id IS NULL) THEN
2684 OracleOn.IC(Y=>icx_call.encrypt2(l_param,-999));
2685 ELSE
2686 OracleOn.IC(Y=>icx_call.encrypt2(l_param,l_session_id));
2687 END IF;
2688
2689 ELSE
2690 -- for bug 1661113
2691 select HOME_URL
2692 into l_url
2693 from ICX_PARAMETERS;
2694
2695 FND_MESSAGE.SET_NAME('SQLAP', 'AP_WEB_NOTIF_LOGON_ERROR');
2696 FND_MESSAGE.SET_TOKEN('URL', l_url);
2697
2698 htp.p('<HTML><BODY>' || FND_MESSAGE.GET || '</BODY></HTML>');
2699
2700 END IF;
2701
2702 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end OpenExp');
2703
2704 EXCEPTION
2705 WHEN OTHERS THEN
2706 htp.p(SQLERRM);
2707 END OpenExp;
2708
2709 ------------------------------------------------------------------------------
2710 PROCEDURE BuildManagerApprvlMessage(p_item_type IN VARCHAR2,
2711 p_item_key IN VARCHAR2,
2712 p_actid IN NUMBER,
2713 p_funmode IN VARCHAR2,
2714 p_result OUT NOCOPY VARCHAR2) IS
2715 ------------------------------------------------------------------------------
2716 l_report_header_id NUMBER;
2717 l_debug_info VARCHAR2(1000);
2718 l_receipts_missing_flag VARCHAR2(1) := 'N';
2719 l_warning_msg VARCHAR2(2000);
2720 l_violation VARCHAR2(1);
2721
2722 /* jrautiai ADJ Fix Start */
2723 l_shortpaid_flag VARCHAR2(1) := 'N';
2724 /* jrautiai ADJ Fix End */
2725
2726 BEGIN
2727
2728 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start BuildManagerApprvlMessage');
2729
2730 IF (p_funmode = 'RUN') THEN
2731
2732 ------------------------------------------------------------
2733 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
2734 ------------------------------------------------------------
2735 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
2736 p_item_key,
2737 'EXPENSE_REPORT_ID');
2738
2739 --chiho:1352284:
2740 ----------------------------------------------------------------
2741 l_debug_info := 'Get the receipts missing flag';
2742 ----------------------------------------------------------------
2743 --chiho:1369557:
2744 IF ( AP_WEB_DB_EXPLINE_PKG.GetReceiptsMissingFlag(
2745 l_report_header_id,
2746 l_receipts_missing_flag) ) THEN
2747
2748 IF ( l_receipts_missing_flag = 'Y' ) THEN
2749
2750 /* jrautiai ADJ Fix Start
2751 * We need to show a message indicating that this is a new report generated due to
2752 * employee requesting approval of shortpaid report due to missing receipts.
2753 * We are assuming here that the only case logic rebuilds the manager approval
2754 * notification while the report was created from another report is due to
2755 * missing receipts.
2756 */
2757
2758 IF AP_WEB_DB_EXPLINE_PKG.GetShortpaidFlag(l_report_header_id, l_shortpaid_flag) THEN
2759 IF (l_shortpaid_flag = 'Y' ) THEN
2760 fnd_message.set_name('SQLAP', 'OIE_WF_APPROVAL_POLICY_NOTE');
2761 l_warning_msg := FND_MESSAGE.Get;
2762
2763 WF_ENGINE.SetItemAttrText(
2764 p_item_type,
2765 p_item_key,
2766 'VIOLATION_NOTE',
2767 WF_ENGINE.GetItemAttrText(p_item_type,
2768 p_item_key,
2769 'VIOLATION_NOTE')||' '|| l_warning_msg );
2770 END IF;
2771 END IF;
2772 /* jrautiai ADJ Fix end */
2773
2774 fnd_message.set_name('SQLAP', 'AP_WEB_EXP_APRVL_RECPTS_MISSIN');
2775 l_warning_msg := FND_MESSAGE.Get;
2776
2777 WF_ENGINE.SetItemAttrText(
2778 p_item_type,
2779 p_item_key,
2780 'VIOLATION_NOTE',
2781 WF_ENGINE.GetItemAttrText(p_item_type,
2782 p_item_key,
2783 'VIOLATION_NOTE')||' '||l_warning_msg );
2784
2785 END IF;
2786 END IF;
2787
2788 IF (AP_WEB_DB_EXPLINE_PKG.AnyPolicyViolation(l_report_header_id)) THEN
2789 fnd_message.set_name('SQLAP', 'AP_WEB_EXP_APRVL_RULES_VIOLATE');
2790 l_warning_msg := FND_MESSAGE.Get;
2791
2792 WF_ENGINE.SetItemAttrText(
2793 p_item_type,
2794 p_item_key,
2795 'VIOLATION_NOTE',
2796 WF_ENGINE.GetItemAttrText(p_item_type,
2797 p_item_key,
2798 'VIOLATION_NOTE')||' '||l_warning_msg );
2799
2800 END IF;
2801
2802
2803 ELSIF (p_funmode = 'CANCEL') THEN
2804
2805 p_result := 'COMPLETE';
2806
2807 END IF;
2808
2809 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end BuildManagerApprvlMessage');
2810
2811 EXCEPTION
2812 WHEN OTHERS THEN
2813 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'BuildManagerApprvlMessage',
2814 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
2815 raise;
2816 END BuildManagerApprvlMessage;
2817
2818 ----------------------------------------------------------------------
2819 PROCEDURE ManagerApproved(p_item_type IN VARCHAR2,
2820 p_item_key IN VARCHAR2,
2821 p_actid IN NUMBER,
2822 p_funmode IN VARCHAR2,
2823 p_result OUT NOCOPY VARCHAR2) IS
2824 ----------------------------------------------------------------------
2825 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
2826 l_debug_info VARCHAR2(200);
2827 BEGIN
2828
2829 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ManagerApproved');
2830
2831 IF (p_funmode = 'RUN') THEN
2832
2833 ------------------------------------------------------------
2834 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
2835 ------------------------------------------------------------
2836 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
2837 p_item_key,
2838 'EXPENSE_REPORT_ID');
2839
2840
2841 ----------------------------------------------------------------
2842 l_debug_info := 'Update the Expense Report as Manager Approved';
2843 ----------------------------------------------------------------
2844 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlag(l_report_header_id)) THEN
2845 NULL;
2846 END IF;
2847
2848 ----------------------------------------------------------
2849 l_debug_info := 'Update Receipts Status to Missing if Pending Resolution';
2850 ----------------------------------------------------------
2851 update ap_expense_report_headers
2852 set receipts_status = 'MISSING'
2853 where report_header_id = l_report_header_id
2854 and receipts_status = 'RESOLUTN';
2855
2856 ELSIF (p_funmode = 'CANCEL') THEN
2857 p_result := 'COMPLETE';
2858 END IF;
2859
2860 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ManagerApproved');
2861
2862 EXCEPTION
2863 WHEN OTHERS THEN
2864 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ManagerApproved',
2865 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
2866 raise;
2867 END ManagerApproved;
2868
2869 ----------------------------------------------------------------------
2870 PROCEDURE CheckSumMissingReceipts(p_item_type IN VARCHAR2,
2871 p_item_key IN VARCHAR2,
2872 p_actid IN NUMBER,
2873 p_funmode IN VARCHAR2,
2874 p_result OUT NOCOPY VARCHAR2) IS
2875 ----------------------------------------------------------------------
2876 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
2877 l_sum_limit NUMBER;
2878 l_sum_violations NUMBER;
2879 l_sum_missing_receipts NUMBER;
2880 l_currency VARCHAR2(50);
2881 l_debug_info VARCHAR2(200);
2882 l_sum_missing_display_total VARCHAR2(50);
2883
2884 BEGIN
2885
2886 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckSumMissingReceipts');
2887
2888 IF (p_funmode = 'RUN') THEN
2889
2890 ------------------------------------------------------------
2891 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
2892 ------------------------------------------------------------
2893 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
2894 p_item_key,
2895 'EXPENSE_REPORT_ID');
2896
2897 ----------------------------------------------------
2898 l_debug_info := 'Retrieve Currency Item Attribute';
2899 ----------------------------------------------------
2900 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
2901 p_item_key,
2902 'CURRENCY');
2903
2904 ---------------------------------------------------------------------------
2905 l_debug_info := 'Retrieve AP Receipt Minnsing Amount Limit Item Attribute';
2906 ---------------------------------------------------------------------------
2907 l_sum_limit := WF_ENGINE.GetActivityAttrNumber(p_item_type,
2908 p_item_key,
2909 p_actid,
2910 'SUM_MISSING_RECEIPTS_LIMIT');
2911
2912 -------------------------------------------------------------------------
2913 l_debug_info := 'Calculate Total Receipt Missing Amt for Expense Report';
2914 -------------------------------------------------------------------------
2915 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetReceiptMissingTotal(l_report_header_id,
2916 l_sum_missing_receipts)) THEN
2917 l_sum_missing_receipts := 0;
2918 END IF;
2919
2920 -------------------------------------------------------------------------
2921 l_debug_info := 'Calculate Total Receipt Violations excluding missing receipt total for Expense Report';
2922 -------------------------------------------------------------------------
2923 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetReceiptViolationsTotal(l_report_header_id,
2924 l_sum_violations)) THEN
2925 l_sum_violations := 0;
2926 END IF;
2927
2928 IF (nvl(l_sum_violations, 0) > 0) THEN
2929 WF_ENGINE.SetItemAttrText(p_item_type,
2930 p_item_key,
2931 'VIOLATIONS_TOTAL',
2932 to_char(l_sum_violations + nvl(l_sum_missing_receipts,0), FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
2933 END IF;
2934
2935
2936 -----------------------------------------------------------------
2937 l_debug_info := 'If Report Amount is Less than AP Limit Return N
2938 otherwise return Y';
2939 -----------------------------------------------------------------
2940 IF (nvl(l_sum_missing_receipts,0) <= nvl(l_sum_limit,0)) THEN
2941
2942 p_result := 'COMPLETE:N';
2943 ELSE
2944 l_sum_missing_display_total := to_char(l_sum_missing_receipts, FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency;
2945
2946 WF_ENGINE.SetItemAttrText(p_item_type,
2947 p_item_key,
2948 'MISSING_RECEIPT_TOTAL',
2949 l_sum_missing_display_total);
2950
2951 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_VERIFY_MISSING_NOTE');
2952 FND_MESSAGE.SET_TOKEN('MISSING_TOTAL',l_sum_missing_display_total);
2953
2954 WF_ENGINE.SetItemAttrText(p_item_type,
2955 p_item_key,
2956 'VERIFY_NOTE',
2957 FND_MESSAGE.GET);
2958
2959
2960
2961 p_result := 'COMPLETE:Y';
2962 END IF;
2963
2964 ELSIF (p_funmode = 'CANCEL') THEN
2965 p_result := 'COMPLETE';
2966 END IF;
2967
2968
2969 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckSumMissingReceipts');
2970
2971 EXCEPTION
2972 WHEN OTHERS THEN
2973 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckSumMissingReceipts',
2974 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
2975 raise;
2976 END CheckSumMissingReceipts;
2977
2978 ----------------------------------------------------------------------
2979 PROCEDURE AnyReceiptRequired(p_item_type IN VARCHAR2,
2980 p_item_key IN VARCHAR2,
2981 p_actid IN NUMBER,
2982 p_funmode IN VARCHAR2,
2983 p_result OUT NOCOPY VARCHAR2) IS
2984 ----------------------------------------------------------------------
2985 l_include_missing_receipts VARCHAR2(1);
2986 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
2987 l_num_req_receipts NUMBER;
2988 l_debug_info VARCHAR2(200);
2989 BEGIN
2990
2991 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AnyReceiptRequired');
2992
2993 IF (p_funmode = 'RUN') THEN
2994
2995 ------------------------------------------------------------
2996 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
2997 ------------------------------------------------------------
2998 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
2999 p_item_key,
3000 'EXPENSE_REPORT_ID');
3001
3002
3003
3004 ------------------------------------------------------------------
3005 l_debug_info := 'Calculate Number of Lines with Receipt Required';
3006 ------------------------------------------------------------------
3007 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumReceiptRequiredLines(
3008 l_report_header_id, l_num_req_receipts)) THEN
3009 l_num_req_receipts := 0;
3010 END IF;
3011
3012 IF (l_num_req_receipts > 0) THEN
3013 ------------------------------------------------------------
3014 l_debug_info := 'Return Y if any line has receipt required';
3015 ------------------------------------------------------------
3016 p_result := 'COMPLETE:Y';
3017 ELSE
3018 p_result := 'COMPLETE:N';
3019 END IF;
3020
3021 ELSIF (p_funmode = 'CANCEL') THEN
3022 p_result := 'COMPLETE';
3023 END IF;
3024
3025 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AnyReceiptRequired');
3026
3027 EXCEPTION
3028 WHEN OTHERS THEN
3029 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AnyReceiptRequired',
3030 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3031 raise;
3032 END AnyReceiptRequired;
3033
3034 ----------------------------------------------------------------------
3035 PROCEDURE AnyJustificationRequired(p_item_type IN VARCHAR2,
3036 p_item_key IN VARCHAR2,
3037 p_actid IN NUMBER,
3038 p_funmode IN VARCHAR2,
3039 p_result OUT NOCOPY VARCHAR2) IS
3040 ----------------------------------------------------------------------
3041 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
3042 l_num_req_receipt NUMBER;
3043 l_violation VARCHAR2(1);
3044 l_debug_info VARCHAR2(200);
3045 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
3046 BEGIN
3047
3048 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AnyJustificationRequired');
3049
3050 IF (p_funmode = 'RUN') THEN
3051
3052 ------------------------------------------------------------
3053 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3054 ------------------------------------------------------------
3055 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3056 p_item_key,
3057 'EXPENSE_REPORT_ID');
3058
3059
3060 ------------------------------------------------------------------------
3061 l_debug_info := 'Calculate Number of Lines With Justification Required';
3062 ------------------------------------------------------------------------
3063 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumJustReqdLines(l_report_header_id,
3064 l_num_req_receipt)) THEN
3065 l_num_req_receipt := 0;
3066 END IF;
3067
3068 ------------------------------------------------------------
3069 l_debug_info := 'Construction the Note';
3070 ------------------------------------------------------------
3071 IF (l_num_req_receipt > 0 ) THEN
3072 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_JUST_REQUIRED_MSG');
3073 END IF;
3074
3075 IF (AP_WEB_DB_EXPLINE_PKG.AnyPolicyViolation(l_report_header_id)) THEN
3076 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_VIOLATION_MSG');
3077 END IF;
3078
3079 IF (l_num_req_receipt > 0 ) AND (l_violation = 'Y' ) THEN
3080 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_JUST_AND_VIOLATION_MSG');
3081 END IF;
3082
3083
3084 l_mess := FND_MESSAGE.GET;
3085 WF_ENGINE.SetItemAttrText(p_item_type,
3086 p_item_key,
3087 'REVIEW_NOTE',
3088 l_mess);
3089
3090 ------------------------------------------------------------
3091 l_debug_info := 'Construction the Instruction';
3092 ------------------------------------------------------------
3093 IF (l_num_req_receipt > 0 OR l_violation = 'Y' ) THEN
3094
3095 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_REVIEW_INSTRUCTION');
3096 l_mess := FND_MESSAGE.GET;
3097
3098 WF_ENGINE.SetItemAttrText(p_item_type,
3099 p_item_key,
3100 'INSTRUCTION',
3101 l_mess);
3102
3103
3104 p_result := 'COMPLETE:Y';
3105 ELSE
3106 p_result := 'COMPLETE:N';
3107 END IF;
3108
3109 ELSIF (p_funmode = 'CANCEL') THEN
3110 p_result := 'COMPLETE';
3111 END IF;
3112
3113 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AnyJustificationRequired');
3114
3115 EXCEPTION
3116 WHEN OTHERS THEN
3117 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AnyJustificationRequired',
3118 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3119 raise;
3120 END AnyJustificationRequired;
3121
3122
3123 ----------------------------------------------------------------------
3124 PROCEDURE CreditLinesOnly(p_item_type IN VARCHAR2,
3125 p_item_key IN VARCHAR2,
3126 p_actid IN NUMBER,
3127 p_funmode IN VARCHAR2,
3128 p_result OUT NOCOPY VARCHAR2) IS
3129 ----------------------------------------------------------------------
3130 l_report_header_id NUMBER;
3131 l_debug_info VARCHAR2(200);
3132 l_new_expense_total NUMBER;
3133 BEGIN
3134
3135 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CreditLinesOnly');
3136
3137 IF (p_funmode = 'RUN') THEN
3138 ----------------------------------------------------------------
3139 l_debug_info := 'Retrieve New Expense Total.';
3140 ----------------------------------------------------------------
3141 l_new_expense_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
3142 p_item_key,
3143 'POS_NEW_EXPENSE_TOTAL');
3144
3145 IF (l_new_expense_total = 0) THEN
3146 p_result := 'COMPLETE:Y';
3147 ELSE
3148 p_result := 'COMPLETE:N';
3149 END IF;
3150
3151
3152 ELSIF (p_funmode = 'CANCEL') THEN
3153 p_result := 'COMPLETE';
3154 END IF;
3155
3156 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CreditLinesOnly');
3157
3158 EXCEPTION
3159 WHEN OTHERS THEN
3160 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CreditLinesOnly',
3161 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3162 raise;
3163
3164 END CreditLinesOnly;
3165
3166
3167
3168
3169 /* This function is used to check if the current process is of the 'old' workflow
3170 which doesn't have the BLOCK activity after the AP_REVIEW_COMPLETE. This code
3171 should be removed after all 10.7 and 11.0.2 customers have upgraded to 11 or 11i.
3172 */
3173 FUNCTION isOldProcess(p_actid IN NUMBER,
3174 p_item_key IN VARCHAR2) return boolean
3175 IS
3176 l_resultType WF_ACTIVITIES.result_type%TYPE;
3177 BEGIN
3178
3179 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start isOldProcess');
3180
3181 select wa.result_type
3182 into l_resultType
3183 from WF_PROCESS_ACTIVITIES WPA, WF_ACTIVITIES WA, wf_items wi
3184 where WPA.INSTANCE_ID = p_actid
3185 and WPA.ACTIVITY_ITEM_TYPE = WA.ITEM_TYPE
3186 and WPA.ACTIVITY_NAME = WA.NAME
3187 and wi.begin_date >= WA.BEGIN_DATE
3188 and wi.begin_date < nvl(WA.END_DATE, wi.begin_date+1)
3189 and wi.item_type = wa.item_type
3190 and wi.item_key = p_item_key;
3191
3192 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end isOldProcess');
3193
3194 --In the 'old' expense report workflow, AP_REVIEW_COMPLETE activity doesn't have result.
3195 if (l_resultType = '*') then
3196 return TRUE;
3197 else
3198 return FALSE;
3199 END IF;
3200 END isOldProcess;
3201
3202
3203 ----------------------------------------------------------------------
3204 PROCEDURE OldAPReviewComplete(p_item_type IN VARCHAR2,
3205 p_item_key IN VARCHAR2,
3206 p_actid IN NUMBER,
3207 p_funmode IN VARCHAR2,
3208 p_result OUT NOCOPY VARCHAR2) IS
3209 ----------------------------------------------------------------------
3210 l_report_header_id NUMBER;
3211 l_ap_review_status VARCHAR2(1);
3212 l_debug_info VARCHAR2(200);
3213 l_wakeup_time DATE;
3214 BEGIN
3215
3216 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start OldAPReviewComplete');
3217
3218 ------------------------------------------------------------
3219 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3220 ------------------------------------------------------------
3221 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3222 p_item_key,
3223 'EXPENSE_REPORT_ID');
3224
3225 l_wakeup_time := (Wf_Engine.GetActivityAttrNumber(p_item_type, p_item_key,
3226 p_actid, 'TIME_INTERVAL_BETWEEN_CHECKS')/24) + sysdate;
3227
3228 ----------------------------------
3229 l_debug_info := 'Set Org Context';
3230 ----------------------------------
3231 AP_WEB_UTILITIES_PKG.ExpenseSetOrgContext(l_report_header_id);
3232
3233 -------------------------------------------------
3234 l_debug_info := 'Retrieve The AP Reviewed Flag';
3235 -------------------------------------------------
3236 SELECT nvl(workflow_approved_flag, 'N')
3237 INTO l_ap_review_status
3238 FROM ap_expense_report_headers
3239 WHERE report_header_id = l_report_header_id;
3240
3241 ------------------------------------------------------------------
3242 l_debug_info := 'Check flag to determine if AP Review Complete and
3243 return Y if so, otherwise N';
3244 ------------------------------------------------------------------
3245 IF (l_ap_review_status = 'Y') THEN
3246 p_result := wf_engine.eng_null;
3247 ELSE
3248 -- Set status of activity to deferred with begin_date set to wakeup_date.
3249 -- For Workflow 1.0 we would call:
3250 -- Wf_Item_Activity_Status.Update_Status(p_item_type, p_item_key,
3251 -- p_actid,'DEFERRED', 'WAITING', l_wakeup_time, null);
3252 -- For Workflow 2.0 (update_status nolonger exists, so we would need to
3253 -- call create_status whose parameters changed from 1.0:
3254 -- Wf_Item_Activity_Status.Update_Status(p_item_type, p_item_key,
3255 -- p_actid,'DEFERRED', 'WAITING', l_wakeup_time, null);
3256 -- Since neither call is compatible for both versions and there's no
3257 -- api to determine which version of workflow is installed, we needed
3258 -- to call the update statement directly.
3259 -- In the future (after Workflow 2.0 production), the Workflow team will
3260 -- provide a new interface that will be compatible for both, like us
3261 -- returning a result of 'DEFERED:l_wakeup_time', and they will take care
3262 -- of running the sql statement.
3263
3264 UPDATE WF_ITEM_ACTIVITY_STATUSES
3265 SET begin_date = l_wakeup_time
3266 WHERE item_type = p_item_type
3267 AND item_key = p_item_key
3268 AND process_activity = p_actid;
3269
3270 p_result := wf_engine.eng_deferred;
3271 END IF;
3272
3273
3274 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end OldAPReviewComplete');
3275
3276 EXCEPTION
3277 WHEN OTHERS THEN
3278 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'OldAPReviewComplete',
3279 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3280 raise;
3281 END OldAPReviewComplete;
3282
3283
3284 ----------------------------------------------------------------------
3285 PROCEDURE APReviewComplete(p_item_type IN VARCHAR2,
3286 p_item_key IN VARCHAR2,
3287 p_actid IN NUMBER,
3288 p_funmode IN VARCHAR2,
3289 p_result OUT NOCOPY VARCHAR2) IS
3290 ----------------------------------------------------------------------
3291 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
3292 l_ap_review_status AP_WEB_DB_EXPRPT_PKG.expHdr_wkflApprvdFlag;
3293 l_debug_info VARCHAR2(200);
3294
3295 l_WorkflowRec AP_WEB_DB_EXPRPT_PKG.ExpWorkflowRec;
3296 C_WF_Version NUMBER := 0;
3297 BEGIN
3298
3299 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start APReviewComplete');
3300
3301 -- Do nothing in cancel mode
3302 IF (p_funmode = wf_engine.eng_cancel) THEN
3303 p_result := wf_engine.eng_null;
3304 return;
3305 end if;
3306
3307
3308 ------------------------------------------------------------
3309 l_debug_info := 'Check for old workflow';
3310 ------------------------------------------------------------
3311 -- Bug 1576769: Should remove this check when there is no 10.7 and 11.0.2 users
3312 IF isOldProcess(p_actid, p_item_key) THEN
3313 OldAPReviewComplete(p_item_type,
3314 p_item_key,
3315 p_actid,
3316 p_funmode,
3317 p_result);
3318 return;
3319 END IF;
3320
3321 -----------------------------------------------------
3322 l_debug_info := 'Get Workflow Version Number';
3323 -----------------------------------------------------
3324 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(p_item_type, p_item_key);
3325
3326 ------------------------------------------------------------
3327 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3328 ------------------------------------------------------------
3329 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3330 p_item_key,
3331 'EXPENSE_REPORT_ID');
3332
3333
3334 -------------------------------------------------
3335 l_debug_info := 'Retrieve The AP Reviewed Flag';
3336 -------------------------------------------------
3337 IF (AP_WEB_DB_EXPRPT_PKG.GetExpWorkflowInfo(l_report_header_id,
3338 l_WorkflowRec)) THEN
3339 l_ap_review_status := nvl(l_WorkflowRec.workflow_flag, 'N');
3340 END IF;
3341
3342 ------------------------------------------------------------------
3343 l_debug_info := 'Check flag to determine if AP Review Complete and
3344 return Y if so, otherwise N';
3345 ------------------------------------------------------------------
3346 IF (l_ap_review_status = 'Y' or
3347 l_ap_review_status = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REJECTED or -- already AP rejected
3348 l_ap_review_status = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REQUEST) THEN -- already AP requests more info
3349 -- p_result := wf_engine.eng_null;
3350 -- dtong changed p_result for bug # 839208
3351 p_result := 'COMPLETE:Y';
3352 ELSE
3353 --bug 7449880: check the version and update expense_status_code
3354 --for reports submitted prior to oie.g, in later releases its updated in
3355 --SetStatusApproverAndDate which is just prior to AP_VERIFY_BLOCK,
3356
3357 IF (C_WF_Version < AP_WEB_EXPENSE_WF.C_OIEH_Version) THEN
3358 -------------------------------------------------------------------
3359 l_debug_info := 'Set Expense Status Code';
3360 -------------------------------------------------------------------
3361 UPDATE ap_expense_report_headers_all
3362 SET expense_status_code = 'MGRAPPR'
3363 WHERE report_header_id = l_report_header_id;
3364 END IF;
3365
3366 -- Set status of activity to deferred with begin_date set to wakeup_date.
3367 -- For Workflow 1.0 we would call:
3368 -- Wf_Item_Activity_Status.Update_Status(p_item_type, p_item_key,
3369 -- p_actid,'DEFERRED', 'WAITING', l_wakeup_time, null);
3370 -- For Workflow 2.0 (update_status nolonger exists, so we would need to
3371 -- call create_status whose parameters changed from 1.0:
3372 -- Wf_Item_Activity_Status.Update_Status(p_item_type, p_item_key,
3373 -- p_actid,'DEFERRED', 'WAITING', l_wakeup_time, null);
3374 -- Since neither call is compatible for both versions and there's no
3375 -- api to determine which version of workflow is installed, we needed
3376 -- to call the update statement directly.
3377 -- In the future (after Workflow 2.0 production), the Workflow team will
3378 -- provide a new interface that will be compatible for both, like us
3379 -- returning a result of 'DEFERED:l_wakeup_time', and they will take care
3380 -- of running the sql statement.
3381 /*
3382 UPDATE WF_ITEM_ACTIVITY_STATUSES
3383 SET begin_date = l_wakeup_time
3384 WHERE item_type = p_item_type
3385 AND item_key = p_item_key
3386 AND process_activity = p_actid;
3387
3388 p_result := wf_engine.eng_deferred;
3389 */
3390 p_result :='COMPLETE:N';
3391 END IF;
3392
3393
3394 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end APReviewComplete');
3395
3396 EXCEPTION
3397 WHEN OTHERS THEN
3398 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'APReviewComplete',
3399 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3400 raise;
3401 END APReviewComplete;
3402
3403
3404 ----------------------------------------------------------------------
3405 PROCEDURE AnyAPAdjustments(p_item_type IN VARCHAR2,
3406 p_item_key IN VARCHAR2,
3407 p_actid IN NUMBER,
3408 p_funmode IN VARCHAR2,
3409 p_result OUT NOCOPY VARCHAR2) IS
3410 ----------------------------------------------------------------------
3411 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
3412 l_orig_expe_report_amt NUMBER;
3413 l_exp_report_amount AP_WEB_DB_EXPRPT_PKG.expHdr_total;
3414 l_orig_exp_report_amt NUMBER;
3415 l_expense_type AP_WEB_DB_EXPTEMPLATE_PKG.expTempl_webFriendlyPrompt;
3416 l_amount AP_WEB_DB_EXPLINE_PKG.expLines_amount;
3417 l_adjustment_reason AP_WEB_DB_EXPLINE_PKG.expLines_adjReason;
3418
3419 l_currency VARCHAR2(50);
3420 l_adjustment_line VARCHAR2(2000);
3421 l_adj_info_body VARCHAR2(2000);
3422 l_debug_info VARCHAR2(200);
3423 l_num_lines INTEGER := 0;
3424 i INTEGER;
3425 j INTEGER;
3426 l_payment_due VARCHAR2(10) := C_IndividualPay;
3427 l_total NUMBER := 0;
3428 l_ccard_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCCardCompany;
3429 l_emp_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee;
3430 C_CreditLineVersion CONSTANT NUMBER := 1;
3431 C_WF_Version NUMBER := 0;
3432
3433 /* jrautiai ADJ Fix Start */
3434 AdjustmentsCursor AP_WEB_DB_EXPLINE_PKG.AdjustmentCursorType;
3435 adjustment_rec AP_WEB_DB_EXPLINE_PKG.AdjustmentRecordType;
3436
3437 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
3438 l_crd_card_count NUMBER := 0;
3439
3440 l_no_receipts_ccard_amt NUMBER := 0;
3441 l_no_receipts_emp_amt NUMBER := 0;
3442 l_policy_ccard_amt NUMBER := 0;
3443 l_policy_emp_amt NUMBER := 0;
3444 l_policy_shortpay_total NUMBER := 0;
3445 /* jrautiai ADJ Fix End */
3446
3447 l_ExpRec AP_WEB_DB_EXPRPT_PKG.ExpInfoRec;
3448 l_reimb_currency ap_expense_report_headers_all.payment_currency_code%type;
3449 BEGIN
3450
3451 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AnyAPAdjustments');
3452
3453 IF (p_funmode = 'RUN') THEN
3454
3455
3456 -----------------------------------------------------
3457 l_debug_info := 'Get Workflow Version Number 2';
3458 -----------------------------------------------------
3459 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
3460
3461 ------------------------------------------------------------
3462 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3463 ------------------------------------------------------------
3464 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3465 p_item_key,
3466 'EXPENSE_REPORT_ID');
3467
3468 ------------------------------------------------------------
3469 l_debug_info := 'Retrieve Currency Item Attribute';
3470 ------------------------------------------------------------
3471 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
3472 p_item_key,
3473 'CURRENCY');
3474
3475 -------------------------------------------------------
3476 l_debug_info := 'Retrieve Orignal Expense Report Total';
3477 -------------------------------------------------------
3478 l_orig_exp_report_amt := WF_ENGINE.GetItemAttrNumber(p_item_type,
3479 p_item_key,
3480 'TOTAL');
3481
3482 ----------------------------------------------------
3483 l_debug_info := 'Retrieve Currency Item Attribute';
3484 ----------------------------------------------------
3485 l_reimb_currency := WF_ENGINE.GetItemAttrText(p_item_type,
3486 p_item_key,
3487 'CURRENCY');
3488
3489 /* jrautiai ADJ Fix Start */
3490 ----------------------------------------------------------------
3491 l_debug_info := 'Set #FROM_ROLE to AP';
3492 ----------------------------------------------------------------
3493 SetFromRoleAP(p_item_type, p_item_key, p_actid, p_funmode, p_result);
3494
3495 ---------------------------------------------------------
3496 l_debug_info := 'Retrieve Payment Due From';
3497 ---------------------------------------------------------
3498 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
3499
3500 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumCCLinesIncluded(l_report_header_id,
3501 l_crd_card_count)) THEN
3502 l_crd_card_count := 0;
3503 END IF;
3504
3505 IF l_payment_due = C_BothPay AND nvl(l_crd_card_count,0) > 0 THEN
3506 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_ADJ_REIMBURSEMENT_INST2');
3507 l_mess := FND_MESSAGE.GET;
3508 ELSE
3509 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_ADJ_REIMBURSEMENT_INST1');
3510 l_mess := FND_MESSAGE.GET;
3511 END IF;
3512
3513 WF_ENGINE.SetItemAttrText(p_item_type,
3514 p_item_key,
3515 'INSTRUCTION',
3516 l_mess);
3517
3518 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_ADJUSTMENT_NOTE');
3519 l_mess := FND_MESSAGE.GET;
3520
3521 WF_ENGINE.SetItemAttrText(p_item_type,
3522 p_item_key,
3523 'WF_NOTE',
3524 l_mess);
3525 /* jrautiai ADJ Fix End */
3526
3527 --------------------------------------------------------
3528 l_debug_info := 'Retrieve Current Expense Report Total';
3529 --------------------------------------------------------
3530 IF (AP_WEB_DB_EXPRPT_PKG.GetReportInfo(l_report_header_id, l_ExpRec)) THEN
3531 l_exp_report_amount := l_ExpRec.total;
3532 ELSE
3533 l_exp_report_amount := 0;
3534 END IF;
3535
3536 --------------------------------------------------------------------------
3537 l_debug_info := 'If Original Total and Current Total Different Then
3538 Adjustment was made, return Y and retrieve adjusted lines';
3539 --------------------------------------------------------------------------
3540 -- bug 3404699:round to reimbursment currency precision
3541 IF (AP_UTILITIES_PKG.Ap_Round_Currency(l_orig_exp_report_amt,l_reimb_currency) <>
3542 l_exp_report_amount OR AP_WEB_DB_EXPLINE_PKG.GetAdjustedLineExists(l_report_header_id)) THEN
3543 p_result := 'COMPLETE:Y';
3544
3545 --------------------------------------------
3546 l_debug_info := 'Calculate Amt Due and Total';
3547 --------------------------------------------
3548 /* jrautiai ADJ Fix Start */
3549 IF (NOT AP_WEB_DB_EXPLINE_PKG.CalculateAmtsDue(l_report_header_id,
3550 l_payment_due,
3551 l_emp_amt,
3552 l_ccard_amt,
3553 l_total)) THEN
3554 l_emp_amt:=0;
3555 l_ccard_amt:=0;
3556 l_total := 0;
3557 END IF;
3558 /* jrautiai ADJ Fix End */
3559
3560 ----------------------------------------------------------
3561 l_debug_info := 'Update the Headers table with the new Amt
3562 Dues and Total columns';
3563 ----------------------------------------------------------
3564 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetAmtDuesAndTotal(
3565 l_report_header_id,
3566 nvl(l_ccard_amt,0),
3567 nvl(l_emp_amt,0),
3568 l_total)) THEN
3569 NULL;
3570 END IF;
3571
3572 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
3573 ------------------------------------------
3574 l_debug_info := 'Open Adjustments Cursor';
3575 ------------------------------------------
3576 -- jrautiai ADJ Fix
3577 IF (AP_WEB_DB_EXPLINE_PKG.GetAdjustmentsCursor(l_report_header_id, 'ADJUSTMENT', AdjustmentsCursor)) THEN
3578 FOR i IN 1..10 LOOP
3579
3580 ------------------------------------------
3581 l_debug_info := 'Fetch Adjustments Cursor';
3582 ------------------------------------------
3583 -- jrautiai ADJ Fix, fetching the results into a record instead of variable.
3584 FETCH AdjustmentsCursor INTO adjustment_rec;
3585 EXIT WHEN AdjustmentsCursor%NOTFOUND;
3586
3587 -----------------------------------------
3588 l_debug_info := 'Format Adjustment Line';
3589 -----------------------------------------
3590 -- jrautiai ADJ Fix, taking the results from a record instead of variable.
3591 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;
3592
3593 -----------------------------------------------------
3594 l_debug_info := 'Set Adjustment Line Item Attribute';
3595 -----------------------------------------------------
3596
3597 WF_ENGINE.SetItemAttrText(p_item_type,
3598 p_item_key,
3599 'ADJ_LINE' || to_char(i),
3600 l_adjustment_line);
3601
3602 l_num_lines := i;
3603 END LOOP;
3604 END IF;
3605
3606 if AdjustmentsCursor%isopen then
3607 CLOSE AdjustmentsCursor;
3608 end if;
3609
3610 END IF;
3611
3612 IF (C_WF_VERSION >= AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
3613
3614 ----------------------------------------------------------
3615 l_debug_info := 'Set Item Attribute Line_Info_Body1';
3616 ---------------------------------------------------------
3617 WF_ENGINE.SetItemAttrText(p_item_type,
3618 p_item_key,
3619 'LINE_INFO_BODY',
3620 'plsql:AP_WEB_EXPENSE_WF.generateAdjustmentInfo/'|| p_item_type || ':' || p_item_key || ':ADJUSTMENT');
3621
3622 ELSE
3623 l_adj_info_body := '';
3624 ---------------------------------------------------------
3625 l_debug_info := 'Populating line_info_body with tokens';
3626 ---------------------------------------------------------
3627 FOR j in 1..l_num_lines LOOP
3628
3629 l_adj_info_body := l_adj_info_body || '
3630 ' || '&' || 'ADJ_LINE' || to_char(j);
3631
3632 END LOOP;
3633
3634 ---------------------------------------------------------
3635 l_debug_info := 'Set Item Attribute Line_Info_Body1';
3636 ---------------------------------------------------------
3637 WF_ENGINE.SetItemAttrText(p_item_type,
3638 p_item_key,
3639 'LINE_INFO_BODY',
3640 l_adj_info_body);
3641 IF (C_WF_Version >= C_CreditLineVersion) THEN
3642 ---------------------------------------------------------
3643 l_debug_info := 'Set Item Attribute Credit_Line_Info_Body1';
3644 ---------------------------------------------------------
3645 WF_ENGINE.SetItemAttrText(p_item_type,
3646 p_item_key,
3647 'CREDIT_LINE_INFO_BODY',
3648 '');
3649 END IF;
3650 END IF;
3651
3652
3653 /* jrautiai ADJ Fix Start */
3654 -----------------------------------------------------
3655 l_debug_info := 'Set New Adjusted Total Item Attribute';
3656 -----------------------------------------------------
3657 WF_ENGINE.SetItemAttrNumber(p_item_type,
3658 p_item_key,
3659 'TOTAL',
3660 l_total);
3661
3662 -----------------------------------------------------------------
3663 l_debug_info := 'Set New Adjusted Display_Total Item Attribute';
3664 -----------------------------------------------------------------
3665 WF_ENGINE.SetItemAttrText(p_item_type,
3666 p_item_key,
3667 'DISPLAY_TOTAL',
3668 to_char(l_total,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
3669
3670 /* jrautiai ADJ Fix end */
3671
3672 IF (C_WF_Version >= C_CreditLineVersion) THEN
3673 -----------------------------------------------------
3674 l_debug_info := 'Set New Credit Total Item Attribute';
3675 -----------------------------------------------------
3676 WF_ENGINE.SetItemAttrNumber(p_item_type,
3677 p_item_key,
3678 'NEG_CREDIT_TOTAL',
3679 0);
3680
3681 -----------------------------------------------------------------
3682 l_debug_info := 'Set New Credit_Display_Total Item Attribute';
3683 -----------------------------------------------------------------
3684 WF_ENGINE.SetItemAttrText(p_item_type,
3685 p_item_key,
3686 'NEG_CREDIT_DISPLAY_TOTAL',
3687 to_char(0,FND_CURRENCY.Get_Format_Mask(l_currency,22)));
3688
3689
3690 -----------------------------------------------------
3691 l_debug_info := 'Set New New_Expense_Total Item Attribute';
3692 -----------------------------------------------------
3693 WF_ENGINE.SetItemAttrNumber(p_item_type,
3694 p_item_key,
3695 'POS_NEW_EXPENSE_TOTAL',
3696 0);
3697
3698 -----------------------------------------------------------------
3699 l_debug_info := 'Set New New_Expense_Display_Total Item Attribute';
3700 -----------------------------------------------------------------
3701 WF_ENGINE.SetItemAttrText(p_item_type,
3702 p_item_key,
3703 'POS_NEW_EXPENSE_DISPLAY_TOTAL',
3704 to_char(0,FND_CURRENCY.Get_Format_Mask(l_currency,22)));
3705
3706
3707 END IF;
3708
3709 ELSE
3710
3711 -------------------------------------------------
3712 l_debug_info := 'Return N if no adjustment made';
3713 -------------------------------------------------
3714 p_result := 'COMPLETE:N';
3715
3716 END IF;
3717
3718 ELSIF (p_funmode = 'CANCEL') THEN
3719
3720 p_result := 'COMPLETE';
3721
3722 END IF;
3723
3724 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AnyAPAdjustments');
3725
3726 EXCEPTION
3727 WHEN OTHERS THEN
3728 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AnyAPAdjustments',
3729 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3730 raise;
3731 END AnyAPAdjustments;
3732
3733 ----------------------------------------------------------------------
3734 PROCEDURE AllReqReceiptsVerified(p_item_type IN VARCHAR2,
3735 p_item_key IN VARCHAR2,
3736 p_actid IN NUMBER,
3737 p_funmode IN VARCHAR2,
3738 p_result OUT NOCOPY VARCHAR2) IS
3739 ----------------------------------------------------------------------
3740 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
3741 l_num_req_receipt_not_verified NUMBER;
3742 l_debug_info VARCHAR2(200);
3743 BEGIN
3744
3745 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AllReqReceiptsVerified');
3746
3747 IF (p_funmode = 'RUN') THEN
3748
3749 ------------------------------------------------------------
3750 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3751 ------------------------------------------------------------
3752 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3753 p_item_key,
3754 'EXPENSE_REPORT_ID');
3755
3756 ----------------------------------------------------------------------
3757 l_debug_info := 'Calculate Number of Lines With Receipt Required that
3758 have not been verified';
3759 ----------------------------------------------------------------------
3760 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumReceiptShortpaidLines(
3761 l_report_header_id,
3762 l_num_req_receipt_not_verified)) THEN
3763 l_num_req_receipt_not_verified := 0;
3764 END IF;
3765
3766 IF (l_num_req_receipt_not_verified > 0) THEN
3767 ----------------------------------------------------------------------
3768 l_debug_info := 'Return N if there exists a line with receipt required
3769 and has not been verified';
3770 ----------------------------------------------------------------------
3771 p_result := 'COMPLETE:N';
3772 ELSE
3773 p_result := 'COMPLETE:Y';
3774 END IF;
3775
3776
3777 ELSIF (p_funmode = 'CANCEL') THEN
3778 p_result := 'COMPLETE';
3779 END IF;
3780
3781 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AllReqReceiptsVerified');
3782
3783 EXCEPTION
3784 WHEN OTHERS THEN
3785 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AllReqReceiptsVerified',
3786 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3787 raise;
3788 END AllReqReceiptsVerified;
3789
3790 ----------------------------------------------------------------------
3791 PROCEDURE AllPassAPApproval(p_item_type IN VARCHAR2,
3792 p_item_key IN VARCHAR2,
3793 p_actid IN NUMBER,
3794 p_funmode IN VARCHAR2,
3795 p_result OUT NOCOPY VARCHAR2) IS
3796 ----------------------------------------------------------------------
3797 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
3798 l_num_req_receipt_not_verified NUMBER;
3799 l_debug_info VARCHAR2(200);
3800 BEGIN
3801
3802 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AllPassAPApproval');
3803
3804 IF (p_funmode = 'RUN') THEN
3805
3806 ------------------------------------------------------------
3807 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3808 ------------------------------------------------------------
3809 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3810 p_item_key,
3811 'EXPENSE_REPORT_ID');
3812
3813
3814 ----------------------------------------------------------------------
3815 l_debug_info := 'Calculate Number of Lines With Receipt Required that
3816 have not been verified';
3817 ----------------------------------------------------------------------
3818 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumShortpaidLines(l_report_header_id,
3819 l_num_req_receipt_not_verified)) THEN
3820 l_num_req_receipt_not_verified := 0;
3821 END IF;
3822
3823 IF (l_num_req_receipt_not_verified > 0) THEN
3824 ----------------------------------------------------------------------
3825 l_debug_info := 'Return N if there exists a line with receipt required
3826 and has not been verified';
3827 ----------------------------------------------------------------------
3828 p_result := 'COMPLETE:N';
3829 ELSE
3830 p_result := 'COMPLETE:Y';
3831 END IF;
3832
3833
3834 ELSIF (p_funmode = 'CANCEL') THEN
3835 p_result := 'COMPLETE';
3836 END IF;
3837
3838 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AllPassAPApproval');
3839
3840 EXCEPTION
3841 WHEN OTHERS THEN
3842 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AllPassAPApproval',
3843 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3844 raise;
3845 END AllPassAPApproval;
3846
3847 ----------------------------------------------------------------------
3848 PROCEDURE Approved(p_item_type IN VARCHAR2,
3849 p_item_key IN VARCHAR2,
3850 p_actid IN NUMBER,
3851 p_funmode IN VARCHAR2,
3852 p_result OUT NOCOPY VARCHAR2) IS
3853 ----------------------------------------------------------------------
3854 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
3855 l_payment_due VARCHAR2(10) := C_IndividualPay;
3856 l_debug_info VARCHAR2(200);
3857 C_WF_Version NUMBER := 0;
3858 BEGIN
3859
3860 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start Approved');
3861
3862 IF (p_funmode = 'RUN') THEN
3863
3864 -----------------------------------------------------
3865 l_debug_info := 'Get Workflow Version Number';
3866 -----------------------------------------------------
3867 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(p_item_type, p_item_key);
3868
3869 ------------------------------------------------------------
3870 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3871 ------------------------------------------------------------
3872 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3873 p_item_key,
3874 'EXPENSE_REPORT_ID');
3875
3876 ---------------------------------------------------------
3877 l_debug_info := 'Retrieve Payment Due From System Option';
3878 ---------------------------------------------------------
3879 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
3880
3881 ------------------------------------------
3882 l_debug_info := 'Call CustomDataTransfer';
3883 ------------------------------------------
3884 AP_WEB_EXPENSE_CUST_WF.CustomDataTransfer(p_item_type,
3885 p_item_key);
3886
3887 ----------------------------------------------------------------------
3888 l_debug_info := 'Update the Expense Report as Approved, if the expense
3889 report has only been manager approved then mark it as
3890 approved automatic';
3891 ----------------------------------------------------------------------
3892 --bug 7449880: check the version and update source for reports submitted
3893 --prior to oie.j, from oiej the source is updated at the end in
3894 --SetStatusApproverAndDate, from oie.g expense_status_code is updated
3895 --at the end in SetStatusApproverAndDate
3896
3897 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_OIEJ_Version) THEN
3898 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(
3899 l_report_header_id, NULL, NULL)) THEN
3900 NULL;
3901 END IF;
3902 ELSE
3903 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(
3904 l_report_header_id, NULL, 'SelfService')) THEN
3905 NULL;
3906 END IF;
3907 END IF;
3908
3909 IF (C_WF_Version < AP_WEB_EXPENSE_WF.C_OIEH_Version) THEN
3910 -------------------------------------------------------------------
3911 l_debug_info := 'Set Expense Status Code';
3912 -------------------------------------------------------------------
3913 UPDATE ap_expense_report_headers_all
3914 SET expense_status_code = 'INVOICED'
3915 WHERE report_header_id = l_report_header_id;
3916 END IF;
3917
3918 ----------------------------------------------------------------------
3919 l_debug_info := 'Update the Credit Card Trxns associated with the Expense
3920 Report as Approved';
3921 ----------------------------------------------------------------------
3922 IF (l_payment_due = C_BothPay OR l_payment_due = C_CompanyPay) THEN
3923 IF (NOT AP_WEB_DB_CCARD_PKG.SetStatus(l_report_header_id, 'APPROVED')) THEN
3924 NULL;
3925 END IF;
3926 END IF;
3927
3928 ELSIF (p_funmode = 'CANCEL') THEN
3929 p_result := 'COMPLETE';
3930 END IF;
3931
3932 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end Approved');
3933
3934 EXCEPTION
3935 WHEN NO_DATA_FOUND THEN
3936 null;
3937 WHEN OTHERS THEN
3938 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'Approved',
3939 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
3940 raise;
3941 END Approved;
3942
3943 ------------------------------------------------------------------------
3944 PROCEDURE SetShortPaidLinesInfo(p_item_type IN VARCHAR2,
3945 p_item_key IN VARCHAR2,
3946 p_actid IN NUMBER,
3947 p_funmode IN VARCHAR2,
3948 p_notification_type IN VARCHAR2,
3949 p_result OUT NOCOPY VARCHAR2) IS
3950 -------------------------------------------------------------------------
3951 l_exp_report_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
3952 l_currency VARCHAR2(15);
3953 l_shortpay_line VARCHAR2(2000);
3954 l_shortpay_info_body VARCHAR2(2000) := '';
3955 l_num_lines NUMBER := 0;
3956 i NUMBER;
3957 j NUMBER;
3958 l_debug_info VARCHAR2(2000);
3959
3960 C_CreditLineVersion CONSTANT NUMBER := 1;
3961 C_WF_Version NUMBER := 0;
3962
3963 -- jrautiai ADJ Fix, changed shortpay to refer the new cursor type.
3964 ShortpaidLinesCursor AP_WEB_DB_EXPLINE_PKG.AdjustmentCursorType;
3965
3966 -- jrautiai ADJ Fix, fetching the shortpay results into a record of a common type.
3967 shortpay_rec AP_WEB_DB_EXPLINE_PKG.AdjustmentRecordType;
3968
3969
3970 BEGIN
3971
3972 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetShortPaidLinesInfo');
3973
3974 -----------------------------------------------------
3975 l_debug_info := 'Get Workflow Version Number 3';
3976 -----------------------------------------------------
3977 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
3978
3979 ------------------------------------------------------------
3980 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
3981 ------------------------------------------------------------
3982 l_exp_report_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
3983 p_item_key,
3984 'EXPENSE_REPORT_ID');
3985
3986 ------------------------------------------------------------
3987 l_debug_info := 'Retrieve Currency Item Attribute';
3988 ------------------------------------------------------------
3989 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
3990 p_item_key,
3991 'CURRENCY');
3992
3993
3994
3995 ----------------------------------
3996 l_debug_info := 'Check to see if the version is before 2.0.3';
3997 ----------------------------------
3998 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
3999 -----------------------------------------------------
4000 l_debug_info := 'Clear Adjustment Line Item Attributes';
4001 -----------------------------------------------------
4002 FOR i IN 1..10 LOOP
4003 WF_ENGINE.SetItemAttrText(p_item_type,
4004 p_item_key,
4005 'ADJ_LINE' || to_char(i),
4006 '');
4007
4008 END LOOP;
4009 END IF;
4010
4011 i := 1;
4012
4013 ------------------------------------------
4014 l_debug_info := 'Open ShortPaidLines Cursor';
4015 ------------------------------------------
4016 -- jrautiai ADJ Fix, using common cursor with adjustments.
4017 IF (AP_WEB_DB_EXPLINE_PKG.GetAdjustmentsCursor(l_exp_report_id, 'SHORTPAY', ShortpaidLinesCursor)) THEN
4018
4019 FOR i IN 1..10 LOOP
4020
4021 ------------------------------------------
4022 l_debug_info := 'Fetch ShortPaidLiness Cursor';
4023 ------------------------------------------
4024 -- jrautiai ADJ Fix, fetching the results into a record instead of variable.
4025 FETCH ShortpaidLinesCursor INTO shortpay_rec;
4026 EXIT WHEN ShortpaidLinesCursor%NOTFOUND;
4027
4028 -----------------------------------------
4029 l_debug_info := 'Format ShortPay Line';
4030 -----------------------------------------
4031 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;
4032
4033 -----------------------------------------------------
4034 l_debug_info := 'Reuse Adjustment Line Item Attribute';
4035 -----------------------------------------------------
4036 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
4037 WF_ENGINE.SetItemAttrText(p_item_type,
4038 p_item_key,
4039 'ADJ_LINE' || to_char(i),
4040 l_shortpay_line);
4041 END IF;
4042 l_num_lines := i;
4043
4044 END LOOP;
4045 END IF;
4046
4047 if ShortpaidLinesCursor%isopen then
4048 CLOSE ShortpaidLinesCursor;
4049 end if;
4050
4051 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
4052 l_shortpay_info_body := '';
4053 ---------------------------------------------------------
4054 l_debug_info := 'Populating line_info_body with tokens ' || to_char(l_num_lines) || '-' || to_char(l_exp_report_id);
4055 ---------------------------------------------------------
4056 FOR j in 1..l_num_lines LOOP
4057 -----------------------------------------------------
4058 l_debug_info := 'Assigning shortpay_info_body';
4059 -----------------------------------------------------
4060
4061 l_shortpay_info_body := l_shortpay_info_body || '
4062 ' || '&' || 'ADJ_LINE' || to_char(j);
4063
4064 END LOOP;
4065 ---------------------------------------------------------
4066 l_debug_info := 'Set Item Attribute Line_Info_Body1';
4067 ---------------------------------------------------------
4068 WF_ENGINE.SetItemAttrText(p_item_type,
4069 p_item_key,
4070 'LINE_INFO_BODY',
4071 l_shortpay_info_body);
4072 ELSE
4073 ---------------------------------------------------------
4074 l_debug_info := 'Set Item Attribute Line_Info_Body1';
4075 ---------------------------------------------------------
4076 -- jrautiai ADJ Fix, Need to be able to distinguish between policy violation and missing receipts notifications.
4077 WF_ENGINE.SetItemAttrText(p_item_type,
4078 p_item_key,
4079 'LINE_INFO_BODY',
4080 'plsql:AP_WEB_EXPENSE_WF.generateAdjustmentInfo/'||p_item_type||':'||p_item_key||':'||NVL(p_notification_type,'SHORTPAY'));
4081
4082 END IF;
4083
4084 IF (C_WF_Version >= C_CreditLineVersion AND
4085 C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
4086 ---------------------------------------------------------
4087 l_debug_info := 'Set Item Attribute Credit_Line_Info_Body1';
4088 ---------------------------------------------------------
4089 WF_ENGINE.SetItemAttrText(p_item_type,
4090 p_item_key,
4091 'CREDIT_LINE_INFO_BODY',
4092 '');
4093 END IF;
4094
4095
4096 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetShortPaidLinesInfo');
4097
4098 EXCEPTION
4099 WHEN OTHERS THEN
4100 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetShortPaidLinesInfo',
4101 p_item_type, p_item_key, null, l_debug_info);
4102 raise;
4103 END SetShortPaidLinesInfo;
4104
4105 -----------------------------------------------------------------------------
4106 PROCEDURE MissingReceiptShortPay(p_item_type IN VARCHAR2,
4107 p_item_key IN VARCHAR2,
4108 p_actid IN NUMBER,
4109 p_funmode IN VARCHAR2,
4110 p_result OUT NOCOPY VARCHAR2)
4111 -----------------------------------------------------------------------------
4112 IS
4113 l_no_receipts_shortpay_id NUMBER;
4114 l_debug_info VARCHAR2(2000);
4115 BEGIN
4116
4117 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start MissingReceiptShortPay');
4118
4119 IF (p_funmode = 'RUN') THEN
4120
4121 ------------------------------------------------------------
4122 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
4123 ------------------------------------------------------------
4124 l_no_receipts_shortpay_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
4125 p_item_key,
4126 'NO_RECEIPTS_SHORTPAY_ID');
4127 IF (l_no_receipts_shortpay_id IS NOT NULL) THEN
4128 p_result := 'COMPLETE:Y';
4129 ELSE
4130 p_result := 'COMPLETE:N';
4131 END IF;
4132
4133 ELSIF (p_funmode = 'CANCEL') THEN
4134
4135 p_result := 'COMPLETE';
4136
4137 NULL;
4138
4139 END IF;
4140
4141 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end MissingReceiptShortPay');
4142
4143 EXCEPTION
4144 WHEN OTHERS THEN
4145 IF (SQLCODE <> -20001) THEN
4146 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
4147 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
4148 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'MissingReceiptShortPay');
4149 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
4150 END IF;
4151 APP_EXCEPTION.RAISE_EXCEPTION;
4152 END MissingReceiptShortPay;
4153
4154 -----------------------------------------------------------------------------
4155 PROCEDURE PolicyViolationShortPay(p_item_type IN VARCHAR2,
4156 p_item_key IN VARCHAR2,
4157 p_actid IN NUMBER,
4158 p_funmode IN VARCHAR2,
4159 p_result OUT NOCOPY VARCHAR2)
4160 -----------------------------------------------------------------------------
4161 IS
4162 l_policy_shortpay_id NUMBER;
4163 l_debug_info VARCHAR2(2000);
4164 BEGIN
4165
4166 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start PolicyViolationShortPay');
4167
4168 IF (p_funmode = 'RUN') THEN
4169
4170 ------------------------------------------------------------
4171 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
4172 ------------------------------------------------------------
4173 l_policy_shortpay_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
4174 p_item_key,
4175 'POLICY_SHORTPAY_ID');
4176 IF (l_policy_shortpay_id IS NOT NULL) THEN
4177 p_result := 'COMPLETE:Y';
4178 ELSE
4179 p_result := 'COMPLETE:N';
4180 END IF;
4181
4182 ELSIF (p_funmode = 'CANCEL') THEN
4183
4184 p_result := 'COMPLETE';
4185
4186 NULL;
4187
4188 END IF;
4189
4190 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end PolicyViolationShortPay');
4191
4192 EXCEPTION
4193 WHEN OTHERS THEN
4194 IF (SQLCODE <> -20001) THEN
4195 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
4196 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
4197 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'PolicyViolationShortPay');
4198 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
4199 END IF;
4200 APP_EXCEPTION.RAISE_EXCEPTION;
4201 END PolicyViolationShortPay;
4202
4203 -----------------------------------------------------------------------------
4204 FUNCTION GetNewShortPayDocumentNum(p_last_document_num IN VARCHAR2) RETURN VARCHAR2 IS
4205 l_new_document_number VARCHAR2(50);
4206 l_position NUMBER;
4207 l_num VARCHAR2(5);
4208 l_debug_info VARCHAR2(2000);
4209 -----------------------------------------------------------------------------
4210 BEGIN
4211
4212 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetNewShortPayDocumentNum');
4213
4214 -------------------------------------------------------------------
4215 l_debug_info := 'Check for _ in the document_number to determine if
4216 the expense report has been short paid before';
4217 -------------------------------------------------------------------
4218 l_position := INSTRB(p_last_document_num, '-');
4219
4220 ------------------------------------------------------------
4221 l_debug_info := 'If position is greater than 0 then expense report
4222 has been short paid, so we need to increment the number
4223 suffix at the end, otherwise the new_document_number
4224 just the old with _1 appended at the end';
4225 ------------------------------------------------------------
4226 IF (l_position > 0) THEN
4227
4228 l_num := to_char(to_number(substrb(p_last_document_num, l_position+1)) + 2);
4229
4230 l_new_document_number := substrb(p_last_document_num,1,l_position) || l_num;
4231 ELSE
4232 l_new_document_number := p_last_document_num || '-1';
4233 END IF;
4234
4235 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetNewShortPayDocumentNum');
4236
4237 return(l_new_document_number);
4238
4239 END GetNewShortPayDocumentNum;
4240
4241 ------------------------------------------------------------------------------
4242 PROCEDURE CreateShortPayExpReport(p_orig_expense_report_id IN AP_WEB_DB_EXPRPT_PKG.expHdr_headerID,
4243 p_new_expense_report_id IN AP_WEB_DB_EXPRPT_PKG.expHdr_headerID,
4244 p_new_expense_report_num IN AP_WEB_DB_EXPRPT_PKG.expHdr_invNum,
4245 p_new_expense_report_total IN AP_WEB_DB_EXPRPT_PKG.expHdr_total,
4246 p_new_ccard_amt IN AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany,
4247 p_new_emp_amt IN AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee,
4248 p_shortpay_type IN VARCHAR2)
4249 ------------------------------------------------------------------------------
4250 IS
4251 l_debug_info VARCHAR2(2000);
4252 l_ExpenseRec AP_WEB_DB_EXPRPT_PKG.XpenseInfoRec;
4253
4254 BEGIN
4255
4256 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CreateShortPayExpReport');
4257
4258 -------------------------------------------------------------------
4259 l_debug_info := 'Create new expense report by creating new record in
4260 ap_expense_report_headers, with same info as old
4261 expense report except new id, number and total';
4262 --------------------------------------------------------------------
4263 l_ExpenseRec.report_header_id := p_new_expense_report_id;
4264 l_ExpenseRec.employee_id := NULL;
4265 l_ExpenseRec.preparer_id := NULL;
4266 l_ExpenseRec.last_updated_by := NULL;
4267 l_ExpenseRec.vouchno := 0;
4268 l_ExpenseRec.total := p_new_expense_report_total;
4269 l_ExpenseRec.vendor_id := NULL;
4270 l_ExpenseRec.vendor_site_id := NULL;
4271 l_ExpenseRec.expense_check_address_flag := NULL;
4272 l_ExpenseRec.document_number := p_new_expense_report_num;
4273 l_ExpenseRec.last_update_login := NULL;
4274 l_ExpenseRec.org_id := NULL;
4275 l_ExpenseRec.workflow_flag := p_shortpay_type;
4276 l_ExpenseRec.amt_due_employee := p_new_emp_amt;
4277 l_ExpenseRec.amt_due_ccard := NVL(p_new_ccard_amt,0);
4278 l_ExpenseRec.description := NULL;
4279 l_ExpenseRec.bothpay_report_header_id := NULL;
4280 l_ExpenseRec.shortpay_parent_id := p_orig_expense_report_id;
4281 l_ExpenseRec.behalf_employee_id := NULL;
4282 l_ExpenseRec.approver_id := NULL;
4283 l_ExpenseRec.week_end_date := NULL;
4284 l_ExpenseRec.set_of_books_id := NULL;
4285 l_ExpenseRec.source := NULL;
4286 l_ExpenseRec.accts_pay_comb_id := NULL;
4287 l_ExpenseRec.expense_status_code := NULL;
4288
4289 IF (NOT AP_WEB_DB_EXPRPT_PKG.InsertReportHeaderLikeExisting(
4290 p_orig_expense_report_id, l_ExpenseRec)) THEN
4291 NULL;
4292 END IF;
4293
4294
4295 IF (p_shortpay_type = 'POLICY') THEN
4296 --------------------------------------------------------------------
4297 l_debug_info := 'Insert the lines that cannot be paid into
4298 ap_expense_report_lines with new report_header_id';
4299 --------------------------------------------------------------------
4300
4301 IF (AP_WEB_DB_EXPLINE_PKG.AddPolicyShortPaidExpLines(p_new_expense_report_id, p_orig_expense_report_id)) THEN
4302 NULL;
4303 END IF;
4304
4305 --------------------------------------------------------------------
4306 l_debug_info := 'Set the report header id of the CC charges that
4307 are attached to the shortpaid report due to policy
4308 violation with the new expense report id';
4309 --------------------------------------------------------------------
4310 IF (NOT AP_WEB_DB_CCARD_PKG.SetCCPolicyShortpaidReportID(p_orig_expense_report_id, p_new_expense_report_id)) THEN
4311 NULL;
4312 END IF;
4313
4314 --------------------------------------------------------------------
4315 l_debug_info := 'Update the report header id in the violations table
4316 with the new expense report id';
4317 --------------------------------------------------------------------
4318 AP_WEB_DB_VIOLATIONS_PKG.SetVioPolicyShortpaidReportID(
4319 p_orig_expense_report_id => p_orig_expense_report_id,
4320 p_new_report_header_id => p_new_expense_report_id);
4321 ELSE
4322
4323 --------------------------------------------------------------------
4324 l_debug_info := 'Insert the lines that cannot be paid into
4325 ap_expense_report_lines with new report_header_id for
4326 missing receipts shortpay';
4327 --------------------------------------------------------------------
4328 IF (AP_WEB_DB_EXPLINE_PKG.AddUnverifiedShortpaidLines(
4329 p_new_expense_report_id, p_orig_expense_report_id)) THEN
4330 NULL;
4331 END IF;
4332
4333 --------------------------------------------------------------------
4334 l_debug_info := 'Set the report header id of the CC charges that
4335 are attached to the shortpaid report due to missing
4336 receipts with the new expense report id';
4337 --------------------------------------------------------------------
4338 IF (NOT AP_WEB_DB_CCARD_PKG.SetCCReceiptShortpaidReportID(
4339 p_orig_expense_report_id, p_new_expense_report_id)) THEN
4340 NULL;
4341 END IF;
4342
4343 --------------------------------------------------------------------
4344 l_debug_info := 'Update the report header id in the violations table
4345 with the new expense report id';
4346 --------------------------------------------------------------------
4347 AP_WEB_DB_VIOLATIONS_PKG.SetVioReceiptShortpaidReportID(
4348 p_orig_expense_report_id => p_orig_expense_report_id,
4349 p_new_report_header_id => p_new_expense_report_id);
4350
4351
4352 END IF;
4353
4354 --------------------------------------------------------------------
4355 l_debug_info := 'Copy Notes from original report';
4356 --------------------------------------------------------------------
4357 AP_WEB_NOTES_PKG.CopyERNotes (
4358 p_src_report_header_id => p_orig_expense_report_id,
4359 p_tgt_report_header_id => p_new_expense_report_id
4360 );
4361
4362
4363 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CreateShortPayExpReport');
4364
4365 EXCEPTION
4366 WHEN OTHERS THEN
4367 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CreateShortPayExpReport',
4368 null, to_char(p_orig_expense_report_id), null, l_debug_info);
4369 raise;
4370 END CreateShortPayExpReport;
4371
4372
4373
4374 ----------------------------------------------------------------------
4375 PROCEDURE SplitExpenseReport(p_item_type IN VARCHAR2,
4376 p_item_key IN VARCHAR2,
4377 p_actid IN NUMBER,
4378 p_funmode IN VARCHAR2,
4379 p_result OUT NOCOPY VARCHAR2) IS
4380 ----------------------------------------------------------------------
4381 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
4382 l_num_req_receipt_not_verified NUMBER;
4383 l_policy_shortpay_total AP_WEB_DB_EXPRPT_PKG.expHdr_total;
4384 l_no_receipts_shortpay_total AP_WEB_DB_EXPRPT_PKG.expHdr_total;
4385 l_policy_shortpay_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
4386 l_no_receipts_shortpay_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
4387 l_policy_shortpay_doc_num AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
4388 l_no_receipts_shortpay_doc_num AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
4389 l_document_number AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
4390 l_payment_due VARCHAR2(10) := C_IndividualPay;
4391 l_count NUMBER;
4392 l_personal_total NUMBER := 0;
4393 l_policy_ccard_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany;
4394 l_no_receipts_ccard_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany;
4395 l_policy_emp_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee;
4396 l_no_receipts_emp_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee;
4397 l_ccard_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany;
4398 l_emp_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee;
4399 l_currency VARCHAR2(50);
4400 l_debug_info VARCHAR2(500);
4401
4402 l_no_data_found_flag1 BOOLEAN := TRUE;
4403 l_no_data_found_flag2 BOOLEAN := TRUE;
4404 l_amtDueCCardCompany AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany;
4405 l_amtDueEmp AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueEmployee;
4406
4407 /* jrautiai ADJ Fix - Start */
4408 l_total NUMBER := 0;
4409 l_policy_count NUMBER := 0;
4410 l_shortpaid_count NUMBER := 0;
4411 l_missing_receipt_count NUMBER := 0;
4412 /* jrautiai ADJ Fix - End */
4413 BEGIN
4414
4415 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SplitExpenseReport');
4416
4417 IF (p_funmode = 'RUN') THEN
4418
4419 ------------------------------------------------------------
4420 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
4421 ------------------------------------------------------------
4422 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
4423 p_item_key,
4424 'EXPENSE_REPORT_ID');
4425
4426 ------------------------------------------------------------
4427 l_debug_info := 'Retrieve Document Number Item Attribute';
4428 ------------------------------------------------------------
4429 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
4430 p_item_key,
4431 'DOCUMENT_NUMBER');
4432
4433 -----------------------------------------------------
4434 l_debug_info := 'Retrieve Currency Item Attribute';
4435 -----------------------------------------------------
4436 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
4437 p_item_key,
4438 'CURRENCY');
4439
4440
4441 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
4442
4443 /* jrautiai ADJ Fix Start */
4444 -----------------------------------------------------------------
4445 l_debug_info := 'Get number of lines not adhereing to policies.';
4446 ------------------------------------------------------------------
4447 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumShortpaidLines(l_report_header_id, l_shortpaid_count)) THEN
4448 l_shortpaid_count := 0;
4449 END IF;
4450
4451 -----------------------------------------------------------------
4452 l_debug_info := 'Get number of lines with policy shortpay.';
4453 ------------------------------------------------------------------
4454 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumPolicyShortpaidLines(l_report_header_id, l_policy_count)) THEN
4455 l_policy_count := 0;
4456 END IF;
4457 /* A line can contain both scenarios, missing receipt and policy violation flag. In that case
4458 * the line is moved to the '-1' report created for the policy violation flag. The variable
4459 * l_shortpaid_count contains the number of lines with either missing receipts and / or with
4460 * policy violation flag. The variable l_policy_count contains lines with only the policy
4461 * violation flag. So the number of lines to be moved to the new missing receipt report
4462 * can be calculated with 'l_shortpaid_count - l_policy_count'. We are not using the function
4463 * AP_WEB_DB_EXPLINE_PKG.GetNumReceiptShortpaidLines
4464 * since that will return all the lines with missing receipts, including ones with also policy
4465 * shortpay flag set to Y, which will not be moved to the missing receipts report.
4466 */
4467 l_missing_receipt_count := l_shortpaid_count - l_policy_count;
4468
4469 IF (l_policy_count > 0) THEN
4470 /* jrautiai ADJ Fix end */
4471
4472 -----------------------------------------------------------------
4473 l_debug_info := 'Retrieve Policy ShortPay New Expense Report Id';
4474 -----------------------------------------------------------------
4475 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetNextExpReportID(l_policy_shortpay_id)) THEN
4476 NULL;
4477 END IF;
4478
4479 l_policy_shortpay_doc_num := l_document_number || '-1';
4480
4481 /* jrautiai ADJ Fix
4482 * Not passing in amounts, they are calculated after the shortpaid report has been created.
4483 * This is because in company pay scenario the personal lines are moved with all the other
4484 * lines using the transaction. If the amounts are calculated prior to creating the report
4485 * and several personal lines exists on the original report the totals incorrectly reflect
4486 * all the personal amounts. */
4487 CreateShortpayExpReport(l_report_header_id,
4488 l_policy_shortpay_id,
4489 l_policy_shortpay_doc_num,
4490 0, --l_policy_shortpay_total,
4491 0, --l_policy_ccard_amt,
4492 0, --l_policy_emp_amt,
4493 'POLICY');
4494
4495 /* jrautiai ADJ Fix Start
4496 * recalculate the shortpaid totals after it has been created*/
4497 IF (NOT AP_WEB_DB_EXPLINE_PKG.CalculateAmtsDue(l_policy_shortpay_id,
4498 l_payment_due,
4499 l_policy_emp_amt,
4500 l_policy_ccard_amt,
4501 l_policy_shortpay_total)) THEN
4502 l_policy_emp_amt:=0;
4503 l_policy_ccard_amt:=0;
4504 l_policy_shortpay_total := 0;
4505 END IF;
4506 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetAmtDuesAndTotal(l_policy_shortpay_id,
4507 l_policy_ccard_amt,
4508 l_policy_emp_amt,
4509 l_policy_shortpay_total)) THEN
4510 NULL;
4511 END IF;
4512 /* jrautiai ADJ Fix End */
4513
4514 ------------------------------------------------------------
4515 l_debug_info := 'Set the New_Expense_Report_ID Item Attribute';
4516 ------------------------------------------------------------
4517 WF_ENGINE.SetItemAttrNumber(p_item_type,
4518 p_item_key,
4519 'POLICY_SHORTPAY_ID',
4520 l_policy_shortpay_id);
4521
4522 WF_ENGINE.SetItemAttrText(p_item_type,
4523 p_item_key,
4524 'POLICY_SHORTPAY_DOC_NUM',
4525 l_policy_shortpay_doc_num);
4526
4527 WF_ENGINE.SetItemAttrNumber(p_item_type,
4528 p_item_key,
4529 'POLICY_SHORTPAY_TOTAL',
4530 l_policy_shortpay_total);
4531
4532
4533 END IF;
4534
4535 IF (l_missing_receipt_count > 0) THEN
4536 -----------------------------------------------------------------
4537 l_debug_info := 'Retrieve Policy ShortPay New Expense Report Id';
4538 -----------------------------------------------------------------
4539 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetNextExpReportID(l_no_receipts_shortpay_id)) THEN
4540 l_no_receipts_shortpay_id := NULL;
4541 END IF;
4542
4543 IF (l_policy_count > 0) THEN
4544 l_no_receipts_shortpay_doc_num := l_document_number || '-2';
4545 ELSE
4546 l_no_receipts_shortpay_doc_num := l_document_number || '-1';
4547 END IF;
4548
4549 /* jrautiai ADJ Fix
4550 * Not passing in amounts, they are calculated after the shortpaid report has been created.
4551 * This is because in company pay scenario the personal lines are moved with all the other
4552 * lines using the transaction. If the amounts are calculated prior to creating the report
4553 * and several personal lines exists on the original report the totals incorrectly reflect
4554 * all the personal amounts. */
4555 CreateShortpayExpReport(l_report_header_id,
4556 l_no_receipts_shortpay_id,
4557 l_no_receipts_shortpay_doc_num,
4558 0,
4559 0,
4560 0,
4561 'NO_RECEIPTS');
4562
4563 /* jrautiai ADJ Fix Start
4564 * recalculate the shortpaid totals after it has been created*/
4565 IF (NOT AP_WEB_DB_EXPLINE_PKG.CalculateAmtsDue(l_no_receipts_shortpay_id,
4566 l_payment_due,
4567 l_no_receipts_emp_amt,
4568 l_no_receipts_ccard_amt,
4569 l_no_receipts_shortpay_total)) THEN
4570 l_no_receipts_emp_amt:=0;
4571 l_no_receipts_ccard_amt:=0;
4572 l_no_receipts_shortpay_total := 0;
4573 END IF;
4574 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetAmtDuesAndTotal(l_no_receipts_shortpay_id,
4575 l_no_receipts_ccard_amt,
4576 l_no_receipts_emp_amt,
4577 l_no_receipts_shortpay_total)) THEN
4578 NULL;
4579 END IF;
4580 /* jrautiai ADJ Fix End */
4581
4582 WF_ENGINE.SetItemAttrNumber(p_item_type,
4583 p_item_key,
4584 'NO_RECEIPTS_SHORTPAY_ID',
4585 l_no_receipts_shortpay_id);
4586
4587 WF_ENGINE.SetItemAttrText(p_item_type,
4588 p_item_key,
4589 'NO_RECEIPTS_SHORTPAY_DOC_NUM',
4590 l_no_receipts_shortpay_doc_num);
4591
4592 WF_ENGINE.SetItemAttrNumber(p_item_type,
4593 p_item_key,
4594 'NO_RECEIPTS_SHORTPAY_TOTAL',
4595 l_no_receipts_shortpay_total);
4596
4597 END IF;
4598
4599
4600 -----------------------------------------------------------------------
4601 l_debug_info := 'Handle the receipts management event MR '||to_char(l_no_receipts_shortpay_id);
4602 -----------------------------------------------------------------------
4603 IF l_no_receipts_shortpay_id IS NOT NULL THEN
4604 AP_WEB_RECEIPT_MANAGEMENT_UTIL.handle_event(l_no_receipts_shortpay_id,AP_WEB_RECEIPT_MANAGEMENT_UTIL.C_EVENT_MR_SHORTPAY);
4605 END IF;
4606
4607 -----------------------------------------------------------------------
4608 l_debug_info := 'Handle the receipts management event PV'||to_char(l_policy_shortpay_id);
4609 -----------------------------------------------------------------------
4610 IF l_policy_shortpay_id IS NOT NULL THEN
4611 AP_WEB_RECEIPT_MANAGEMENT_UTIL.handle_event(l_policy_shortpay_id,AP_WEB_RECEIPT_MANAGEMENT_UTIL.C_EVENT_PV_SHORTPAY);
4612 END IF;
4613
4614 -----------------------------------------------------------------------
4615 l_debug_info := 'Handle the receipts management event original';
4616 -----------------------------------------------------------------------
4617 AP_WEB_RECEIPT_MANAGEMENT_UTIL.handle_event(l_report_header_id,AP_WEB_RECEIPT_MANAGEMENT_UTIL.C_EVENT_SHORTPAY);
4618
4619 -----------------------------------------------------------------------
4620 l_debug_info := 'Count the lines remaining in the original expense
4621 report';
4622 -----------------------------------------------------------------------
4623 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumberOfExpLines(l_report_header_id,l_count) OR l_count = 0) THEN
4624 -----------------------------------------
4625 l_debug_info := 'Delete the original expense report if everything
4626 is getting shortpaid';
4627 ----------------------------------------------------------------------
4628 IF (NOT AP_WEB_DB_EXPRPT_PKG.DeleteExpenseReport(l_report_header_id)) THEN
4629 NULL;
4630 END IF;
4631
4632 ELSE
4633
4634 ----------------------------------------------------------------------
4635 l_debug_info := 'Update the total of the original expense report
4636 to not include the amount of the new expense report';
4637 ----------------------------------------------------------------------
4638 /* jrautiai ADJ Fix Start */
4639 IF (NOT AP_WEB_DB_EXPLINE_PKG.CalculateAmtsDue(l_report_header_id,
4640 l_payment_due,
4641 l_amtDueEmp,
4642 l_amtDueCCardCompany,
4643 l_total)) THEN
4644 l_amtDueEmp:=0;
4645 l_amtDueCCardCompany:=0;
4646 l_total := 0;
4647 END IF;
4648
4649 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetAmtDuesAndTotal(l_report_header_id,
4650 l_amtDueCCardCompany,
4651 l_amtDueEmp,
4652 l_total)) THEN
4653 /* jrautiai ADJ Fix End */
4654 NULL;
4655 END IF;
4656
4657 END IF;
4658
4659 ELSIF (p_funmode = 'CANCEL') THEN
4660
4661 p_result := 'COMPLETE';
4662
4663 END IF;
4664
4665 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SplitExpenseReport');
4666
4667 EXCEPTION
4668 WHEN OTHERS THEN
4669 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SplitExpenseReport',
4670 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
4671 raise;
4672 END SplitExpenseReport;
4673
4674
4675
4676 PROCEDURE DeleteExpReportFromAPTables(p_report_header_id IN AP_WEB_DB_EXPRPT_PKG.expHdr_headerID) IS
4677 l_debug_info VARCHAR2(200);
4678 l_payment_due VARCHAR2(10) := C_IndividualPay;
4679 l_item_type VARCHAR2(100) := 'APEXP';
4680 l_item_key VARCHAR2(100) := to_char(p_report_header_id);
4681
4682 BEGIN
4683
4684 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start DeleteExpReportFromAPTables');
4685
4686 ----------------------------------------------------------------
4687 l_debug_info := 'Retrive the Payment Due From Profile Option';
4688 ----------------------------------------------------------------
4689 l_payment_due := WF_ENGINE.GetItemAttrText(l_item_type,
4690 l_item_key,'PAYMENT_DUE_FROM');
4691
4692 ---------------------------------------------------------------------
4693 l_debug_info := 'Update manager rejected/returned credit card transactions that
4694 are deleted after a timeout';
4695 ---------------------------------------------------------------------
4696 IF (l_payment_due = C_BothPay OR l_payment_due = C_CompanyPay) THEN
4697 IF (NOT AP_WEB_DB_CCARD_PKG.ResetCCMgrRejectedCCLines(p_report_header_id)) THEN
4698 NULL;
4699 END IF;
4700 END IF;
4701
4702
4703
4704 ---------------------------------------------------------------------------
4705 l_debug_info := 'Update shortpaid credit card transactions';
4706 ---------------------------------------------------------------------------
4707 IF (NOT AP_WEB_DB_CCARD_PKG.ResetCCLines(p_report_header_id)) THEN
4708 NULL;
4709 END IF;
4710
4711 ---------------------------------------------------------------------------
4712 l_debug_info := 'Delete the expense lines for the given expense report id';
4713 ---------------------------------------------------------------------------
4714 IF (NOT AP_WEB_DB_EXPLINE_PKG.DeleteReportLines(p_report_header_id)) THEN
4715 NULL;
4716 END IF;
4717
4718 ----------------------------------------------------
4719 l_debug_info := 'Delete the expense report header';
4720 ----------------------------------------------------
4721 IF (NOT AP_WEB_DB_EXPRPT_PKG.DeleteExpenseReport(p_report_header_id)) THEN
4722 NULL;
4723 END IF;
4724
4725 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end DeleteExpReportFromAPTables');
4726
4727 EXCEPTION
4728 WHEN OTHERS THEN
4729 IF (SQLCODE <> -20001) THEN
4730 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
4731 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
4732 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'DeleteExpReportFromAPTables');
4733 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
4734 END IF;
4735 APP_EXCEPTION.RAISE_EXCEPTION;
4736 END DeleteExpReportFromAPTables;
4737
4738 ---------------------------------------------------
4739 PROCEDURE ResetAttrValues(p_item_type IN VARCHAR2,
4740 p_item_key IN VARCHAR2,
4741 p_actid IN NUMBER) IS
4742 ---------------------------------------------------
4743 --
4744 -- Reset the attribute values which are not set explicitly by
4745 -- StartExpenseReportProcess before the rejected/returned report is resubmitted.
4746 -- We need to clear these because we will be revisiting nodes in the process.
4747 --
4748
4749 I NUMBER;
4750 l_debug_info VARCHAR2(200);
4751 C_WF_VERSION NUMBER := 0;
4752 -- Bug 668037
4753 l_override_approver_id AP_WEB_DB_EXPRPT_PKG.expHdr_overrideApprID;
4754
4755 BEGIN
4756
4757 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetAttrValues');
4758
4759 C_WF_VERSION := GetFlowVersion(p_item_type, p_item_key);
4760 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
4761 -----------------------------------------------------
4762 l_debug_info := 'Unset Adjustment Line Item Attribute';
4763 -----------------------------------------------------
4764 FOR I IN 1..C_NUM_ADJ_LINE_ATTRS LOOP
4765
4766 WF_ENGINE.SetItemAttrText(p_item_type,
4767 p_item_key,
4768 'ADJ_LINE' || to_char(I),
4769 '');
4770
4771 END LOOP;
4772 ELSE
4773 WF_ENGINE.SetItemAttrText(p_item_type,
4774 p_item_key,
4775 'LINE_INFO_BODY',
4776 'plsql:AP_WEB_EXPENSE_WF.resetLineInfo/');
4777 END IF;
4778
4779 ----------------------------------------------------------------
4780 l_debug_info := 'Unset error message';
4781 -----------------------------------------------------------------
4782 WF_ENGINE.SetItemAttrText(p_item_type,
4783 p_item_key,
4784 'ERROR_MESSAGE',
4785 '');
4786
4787
4788
4789 ----------------------------------------------------------------------
4790 l_debug_info := 'Unset Find Approver Count';
4791 ----------------------------------------------------------------------
4792 WF_ENGINE.SetItemAttrNumber(p_item_type,
4793 p_item_key,
4794 'FIND_APPROVER_COUNT',
4795 0);
4796
4797 ----------------------------------------------------------------------
4798 l_debug_info := 'Unset Forward_From Item Attributes With Approver Info';
4799 ----------------------------------------------------------------------
4800 WF_ENGINE.SetItemAttrText(p_item_type,
4801 p_item_key,
4802 'FORWARD_FROM_DISPLAY_NAME',
4803 '');
4804
4805 WF_ENGINE.SetItemAttrNUMBER(p_item_type,
4806 p_item_key,
4807 'FORWARD_FROM_ID',
4808 '');
4809
4810 WF_ENGINE.SetItemAttrText(p_item_type,
4811 p_item_key,
4812 'FORWARD_FROM_NAME',
4813 '');
4814
4815 IF (C_WF_VERSION < AP_WEB_EXPENSE_WF.C_NoMultiLineVersion) THEN
4816 ------------------------------------------------------------------------
4817 l_debug_info := 'Set Line_Info Item Attribute with formatted expense line';
4818 ---------------------------------------------------------------------------
4819 FOR I IN 1..200 LOOP
4820
4821 WF_ENGINE.SetItemAttrText(p_item_type,
4822 p_item_key,
4823 'LINE_INFO' || TO_CHAR(I),
4824 '');
4825
4826 END LOOP;
4827 ---------------------------------------------------------
4828 l_debug_info := 'Unset Item Attribute Line_Info_Body1';
4829 ---------------------------------------------------------
4830 WF_ENGINE.SetItemAttrText(p_item_type,
4831 p_item_key,
4832 'LINE_INFO_BODY',
4833 '');
4834
4835 END IF;
4836
4837 --------------------------------------------------------------------------
4838 l_debug_info := 'Reset
4839 Manager_Approval_Send_Count Item Attribute and return Y';
4840 --------------------------------------------------------------------------
4841 WF_ENGINE.SetItemAttrNumber(p_item_type,
4842 p_item_key,
4843 'MANAGER_APPROVAL_SEND_COUNT',
4844 0);
4845
4846 ---------------------------------------------------------------
4847 l_debug_info := 'Unset Manager_Display_Name Info Item Attribute';
4848 ---------------------------------------------------------------
4849 WF_ENGINE.SetItemAttrText(p_item_type,
4850 p_item_key,
4851 'MANAGER_DISPLAY_NAME',
4852 '');
4853
4854 --------------------------------------------------------
4855 l_debug_info := 'Unset Manager_ID Info Item Attribute';
4856 --------------------------------------------------------
4857 WF_ENGINE.SetItemAttrText(p_item_type,
4858 p_item_key,
4859 'MANAGER_ID',
4860 '');
4861
4862 --------------------------------------------------------
4863 l_debug_info := 'Unset Manager_Name Info Item Attribute';
4864 --------------------------------------------------------
4865 WF_ENGINE.SetItemAttrText(p_item_type,
4866 p_item_key,
4867 'MANAGER_NAME',
4868 '');
4869
4870
4871 -----------------------------------------------------------------
4872 l_debug_info := 'Unset Missing Receipt Total';
4873 -----------------------------------------------------------------
4874 WF_ENGINE.SetItemAttrText(p_item_type,
4875 p_item_key,
4876 'MISSING_RECEIPT_TOTAL',
4877 '');
4878
4879 ---------------------------------------------------------------
4880 l_debug_info := 'Reset rejection reason';
4881 ---------------------------------------------------------------
4882 WF_ENGINE.SetItemAttrText(p_item_type,
4883 p_item_key,
4884 'WF_NOTE',
4885 '');
4886
4887 ---------------------------------------------------------------
4888 l_debug_info := 'Reset violation note';
4889 ---------------------------------------------------------------
4890 WF_ENGINE.SetItemAttrText(p_item_type,
4891 p_item_key,
4892 'VIOLATION_NOTE',
4893 '');
4894
4895 ---------------------------------------------------------------
4896 l_debug_info := 'Reset Employee violation note';
4897 ---------------------------------------------------------------
4898 WF_ENGINE.SetItemAttrText(p_item_type,
4899 p_item_key,
4900 'EMP_VIOLATION_NOTE',
4901 '');
4902
4903 ---------------------------------------------------------------
4904 l_debug_info := 'Reset violation total';
4905 ---------------------------------------------------------------
4906 WF_ENGINE.SetItemAttrText(p_item_type,
4907 p_item_key,
4908 'VIOLATIONS_TOTAL',
4909 '');
4910
4911 --Bug 4425821: Uptake AME parallel approvers
4912 ---------------------------------------------------------------
4913 l_debug_info := 'Reset AME Approver Response';
4914 ---------------------------------------------------------------
4915 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_R120_Version) THEN
4916 WF_ENGINE.SetItemAttrText(p_item_type,
4917 p_item_key,
4918 'AME_APPROVER_RESPONSE',
4919 '');
4920 WF_ENGINE.SetItemAttrText(p_item_type,
4921 p_item_key,
4922 'AME_REJECTED_CHILD_ITEM_KEY',
4923 '');
4924 END IF;
4925
4926 --
4927 -- Bug 668037
4928 -- Reset approver attributes
4929 --
4930 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetOverrideApproverID(to_number(p_item_key), l_override_approver_id)) THEN
4931 l_override_approver_id := NULL;
4932 END IF;
4933
4934 IF (l_override_approver_id IS NOT NULL) THEN
4935 AP_WEB_EXPENSE_WF.SetPersonAs(l_override_approver_id,
4936 p_item_type,
4937 p_item_key,
4938 'APPROVER');
4939 ELSE
4940 --------------------------------------------------------
4941 l_debug_info := 'Set Approver_ID Info Item Attribute';
4942 --------------------------------------------------------
4943 WF_ENGINE.SetItemAttrText(p_item_type,
4944 p_item_key,
4945 'APPROVER_ID',
4946 null);
4947
4948 --------------------------------------------------------
4949 l_debug_info := 'Set Approver_Name Info Item Attribute';
4950 --------------------------------------------------------
4951 WF_ENGINE.SetItemAttrText(p_item_type,
4952 p_item_key,
4953 'APPROVER_NAME',
4954 '');
4955
4956 ----------------------------------------------------------------
4957 l_debug_info := 'Set Approver_Display_Name Info Item Attribute';
4958 ----------------------------------------------------------------
4959 WF_ENGINE.SetItemAttrText(p_item_type,
4960 p_item_key,
4961 'APPROVER_DISPLAY_NAME',
4962 '');
4963 END IF;
4964
4965 ----------------------------------------------------------------
4966 l_debug_info := 'Reset AP Validation Attributes';
4967 ----------------------------------------------------------------
4968 ResetAPValidationAttrValues(p_item_type,
4969 p_item_key,
4970 p_actid);
4971
4972 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetAttrValues');
4973
4974 EXCEPTION
4975 WHEN OTHERS THEN
4976 NULL;
4977 END ResetAttrValues;
4978
4979 /*----------------------------------------------------------------------------*
4980 | Procedure |
4981 | ResetCCardTxns |
4982 | |
4983 | DESCRIPTION |
4984 | Private procedure for resetting credit card transactions |
4985 | PARAMETERS |
4986 | INPUT |
4987 | p_report_header_id NUMBER -- Expense Report Header ID |
4988 | RETURNS |
4989 | none |
4990 *----------------------------------------------------------------------------*/
4991
4992 PROCEDURE ResetCCardTxns (
4993 p_report_header_id IN AP_WEB_DB_EXPLINE_PKG.expLines_headerID,
4994 p_item_type IN VARCHAR2,
4995 p_item_key IN VARCHAR2)
4996 IS
4997 l_payment_due VARCHAR2(50) := C_IndividualPay;
4998 l_debug_info VARCHAR2(200);
4999 BEGIN
5000
5001 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF',
5002 'start ResetCCardTxns');
5003
5004 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type, p_item_key,
5005 'PAYMENT_DUE_FROM');
5006
5007 l_debug_info := 'Update for Credit Card Integration';
5008 IF (l_payment_due = C_CompanyPay) THEN
5009 IF (NOT AP_WEB_DB_EXPLINE_PKG.DeletePersonalLines(p_report_header_id))
5010 THEN
5011 NULL;
5012 END IF;
5013 END IF;
5014
5015 /* Bug 2356968. When an expense report contains a Personal CC txn, and if
5016 the approver rejects that Expense Report upon submission, the following
5017 call to ResetMgrRejectPersonalTrxns will remove the Personal CC txn
5018 from the expense report, whereby it becomes part of the common queue again
5019 allowing other users to use the same CC txn on other expense reports. Hence
5020 commenting the call because the expense report should maintian its original
5021 data on rejected reports.
5022 l_debug_info := 'Update for Credit Card Integration Bothpay';
5023 IF (l_payment_due = C_CompanyPay OR
5024 l_payment_due = AP_WEB_EXPENSE_WF.C_BothPay) THEN
5025 IF (NOT AP_WEB_DB_CCARD_PKG.ResetMgrRejectPersonalTrxns(
5026 p_report_header_id)) THEN
5027 NULL;
5028 END IF;
5029 END IF;
5030 */
5031
5032 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF',
5033 'end ResetCCardTxns');
5034
5035 EXCEPTION
5036 WHEN OTHERS THEN
5037 ROLLBACK;
5038 APP_EXCEPTION.RAISE_EXCEPTION;
5039 END ResetCCardTxns;
5040
5041 PROCEDURE AMEAbortRequestApprovals(p_rep_header_id IN AP_WEB_DB_EXPLINE_PKG.expLines_headerID)
5042 IS
5043 l_debug_info VARCHAR2(200);
5044 l_wf_active BOOLEAN := FALSE;
5045 l_wf_exist BOOLEAN := FALSE;
5046 l_end_date wf_items.end_date%TYPE;
5047 l_childItemKeySeq NUMBER;
5048 l_childItemKey varchar2(30);
5049 l_itemkey varchar2(30);
5050 l_itemtype varchar2(30);
5051 l_AmeRejectedChildItemKey varchar2(30);
5052 BEGIN
5053
5054 l_itemtype := 'APEXP';
5055 l_itemkey := to_char(p_rep_header_id);
5056
5057 ---------------------------------------------
5058 l_debug_info := 'Start AMEAbortRequestApprovals';
5059 ---------------------------------------------
5060 l_childItemKeySeq := WF_ENGINE.GetItemAttrNumber(l_itemtype,
5061 l_itemkey,
5062 'AME_CHILD_ITEM_KEY_SEQ');
5063
5064 l_AmeRejectedChildItemKey := WF_ENGINE.GetItemAttrText(l_itemtype,
5065 l_itemkey,
5066 'AME_REJECTED_CHILD_ITEM_KEY');
5067
5068 if (l_childItemKeySeq >= 1) then
5069
5070 FOR i in 1 .. l_childItemKeySeq LOOP
5071 l_childItemKey := l_itemkey || '-' || to_char(i);
5072 l_end_date := null;
5073 l_wf_active := FALSE;
5074 l_wf_exist := FALSE;
5075
5076 ---------------------------------------------------------------------------
5077 l_debug_info := 'l_childItemKey :' || l_childItemKey;
5078 l_debug_info := 'l_AmeRejectedChildItemKey: ' || l_AmeRejectedChildItemKey;
5079 ---------------------------------------------------------------------------
5080
5081 if ((l_AmeRejectedChildItemKey is null) or (l_childItemKey <> l_AmeRejectedChildItemKey)) then
5082
5083 begin
5084 select end_date
5085 into l_end_date
5086 from wf_items
5087 where item_type = l_itemtype
5088 and item_key = l_childItemKey;
5089
5090 if l_end_date is NULL then
5091 l_wf_active := TRUE;
5092 else
5093 l_wf_active := FALSE;
5094 end if;
5095 l_wf_exist := TRUE;
5096 exception
5097 when no_data_found then
5098 l_wf_active := FALSE;
5099 l_wf_exist := FALSE;
5100 end;
5101
5102 if l_wf_exist then
5103
5104 if l_wf_active then
5105 --------------------------------------------------------
5106 l_debug_info := 'Abort Child Process' || l_childItemKey;
5107 --------------------------------------------------------
5108 wf_engine.AbortProcess (itemtype => l_itemtype,
5109 itemkey => l_childItemKey,
5110 cascade => TRUE);
5111 end if;
5112
5113 ---------------------------------------------------------
5114 l_debug_info := 'Purge child workflow' || l_childItemKey;
5115 ---------------------------------------------------------
5116 wf_purge.Items(itemtype => l_itemtype,
5117 itemkey => l_childItemKey);
5118
5119 wf_purge.TotalPerm(itemtype => l_itemtype,
5120 itemkey => l_childItemKey,
5121 runtimeonly => TRUE);
5122
5123 ---------------------------------------------------------------
5124 l_debug_info := 'After Purge child workflow' || l_childItemKey;
5125 ---------------------------------------------------------------
5126
5127 end if;
5128 end if;
5129
5130 END LOOP;
5131
5132 end if;
5133 END AMEAbortRequestApprovals;
5134
5135 ----------------------------------------------------------------------
5136 PROCEDURE SetRejectStatusAndResetAttr(p_item_type IN VARCHAR2,
5137 p_item_key IN VARCHAR2,
5138 p_actid IN NUMBER,
5139 p_funmode IN VARCHAR2,
5140 p_result OUT NOCOPY VARCHAR2) IS
5141 ----------------------------------------------------------------------
5142 l_debug_info VARCHAR2(200);
5143 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
5144 l_payment_due VARCHAR2(10) := C_IndividualPay;
5145 l_AMEEnabled VARCHAR2(1);
5146 l_No VARCHAR2(1) := 'N';
5147 C_WF_Version NUMBER := 0;
5148 l_n_resp_id NUMBER;
5149 BEGIN
5150
5151 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetRejectStatusAndResetAttr');
5152
5153 IF (p_funmode = 'RUN') THEN
5154
5155 -----------------------------------------------------
5156 l_debug_info := 'Get Workflow Version Number';
5157 -----------------------------------------------------
5158 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(p_item_type, p_item_key);
5159
5160 ------------------------------------------------------------
5161 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
5162 ------------------------------------------------------------
5163 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5164 p_item_key,
5165 'EXPENSE_REPORT_ID');
5166
5167 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
5168
5169 ------------------------------------------------------------
5170 l_debug_info := 'Set reject status in report header';
5171 ------------------------------------------------------------
5172 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(l_report_header_id,
5173 AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REJECTED,
5174 'NonValidatedWebExpense')) THEN
5175 NULL;
5176 END IF;
5177
5178 /* This is required for AME integration with Expenses in 11i
5179 In 11, this procedure is only a stub */
5180 /*
5181 AP_WEB_WRAPPER_PKG.SetRejectStatusInAME(p_item_key,
5182 p_item_type);*/
5183
5184 -- Bug 3560082 - Comment the call to SetRejectStatusInAME and add the call
5185 -- AME_API.clearAllApprovals
5186 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
5187 p_item_key,
5188 'AME_ENABLED');
5189 IF (l_AMEEnabled = 'Y') THEN
5190 --Bug 4425821: Uptake AME parallel approvers
5191 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_R120_Version) THEN
5192 ---------------------------------------------------------------------------
5193 l_debug_info := 'Call AMEAbortRequestApprovals' || to_char(l_report_header_id);
5194 ---------------------------------------------------------------------------
5195 AMEAbortRequestApprovals(l_report_header_id);
5196 END IF;
5197
5198 -----------------------------------------------------------------
5199 l_debug_info := 'Call clearAllApprovals' || to_char(p_item_key) ;
5200 -----------------------------------------------------------------
5201 AME_API2.clearAllApprovals(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
5202 transactionIdIn => p_item_key,
5203 transactionTypeIn => p_item_type);
5204
5205 END IF;
5206
5207 -----------------------------------------------------------------
5208 l_debug_info := 'Call AP_WEB_AUDIT_QUEUE_UTILS.remove_from_queue';
5209 -----------------------------------------------------------------
5210 AP_WEB_AUDIT_QUEUE_UTILS.remove_from_queue(l_report_header_id);
5211
5212 ----------------------------------------------------------
5213 l_debug_info := 'Clearing out lines in AP_AUD_AUDIT_REASONS';
5214 ----------------------------------------------------------
5215 -- Bug 4394168
5216 AP_WEB_AUDIT_UTILS.clear_audit_reason_codes(l_report_header_id);
5217
5218 ------------------------------------------------------------
5219 l_debug_info := 'call reset credit card transactions';
5220 ------------------------------------------------------------
5221 ResetCCardTxns(l_report_header_id, p_item_type, p_item_key);
5222
5223 -- 4001778/3654956 : reset the Apply Advances
5224 --5060928: reset the Apply Advnaces only if OIE:Enable Advances = "Payables"
5225
5226 begin
5227
5228 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5229 p_item_key,
5230 'RESPONSIBILITY_ID');
5231
5232 exception
5233 when others then
5234 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
5235 null;
5236 else
5237 raise;
5238 end if;
5239 end;
5240
5241 IF FND_PROFILE.VALUE_SPECIFIC('OIE_ENABLE_ADVANCES',NULL,l_n_resp_id,200) = 'PAYABLES' THEN
5242
5243 AP_WEB_DB_EXPLINE_PKG.resetApplyAdvances(l_report_header_id);
5244 END IF;
5245
5246
5247 /* Bug 4019412 */
5248 AP_WEB_DB_EXPLINE_PKG.resetAPflags(l_report_header_id);
5249
5250 ------------------------------------------------------------
5251 l_debug_info := 'Set which process to start from';
5252 ------------------------------------------------------------
5253 -- Indicate which process to start from
5254 -- (skip ServerValidate, Manager Approval)
5255 WF_ENGINE.SetItemAttrText(p_item_type,
5256 p_item_key,
5257 'START_FROM_PROCESS',
5258 C_START_FROM_SERVER_VALIDATION);
5259
5260 -- Reset the attributes which will not be set by code to initialize a
5261 -- process
5262 ----------------------------------------------------------
5263 l_debug_info := 'Reset attribute';
5264 ----------------------------------------------------------
5265 ResetAttrValues(p_item_type, p_item_key, p_actid);
5266
5267 ----------------------------------------------------------
5268 l_debug_info := 'Reset Receipt Verified Flag to N';
5269 ----------------------------------------------------------
5270 -- Bug 4094871
5271 begin
5272 update ap_expense_report_lines
5273 set receipt_verified_flag = l_No
5274 where report_header_id = l_report_header_id;
5275 exception
5276 when others then null;
5277 end;
5278
5279 -----------------------------------------------
5280 l_debug_info := 'Raise Receipts Aborted Event';
5281 -----------------------------------------------
5282 AP_WEB_RECEIPTS_WF.RaiseAbortedEvent(l_report_header_id);
5283
5284 -----------------------------------------------------
5285 l_debug_info := 'After Raise Receipts Aborted Event';
5286 -----------------------------------------------------
5287 p_result := 'COMPLETE:Y';
5288 ELSIF (p_funmode = 'CANCEL') THEN
5289 p_result := 'COMPLETE';
5290 END IF;
5291
5292 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetRejectStatusAndResetAttr');
5293
5294 EXCEPTION
5295 WHEN OTHERS THEN
5296 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetRejectStatusAndResetAttr',
5297
5298 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
5299 RAISE;
5300
5301 END SetRejectStatusAndResetAttr;
5302
5303 ----------------------------------------------------------------------
5304 PROCEDURE DeleteExpenseReport(p_item_type IN VARCHAR2,
5305 p_item_key IN VARCHAR2,
5306 p_actid IN NUMBER,
5307 p_funmode IN VARCHAR2,
5308 p_result OUT NOCOPY VARCHAR2) IS
5309 ----------------------------------------------------------------------
5310 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
5311 l_debug_info VARCHAR2(200);
5312 BEGIN
5313
5314 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start DeleteExpenseReport');
5315
5316 IF (p_funmode = 'RUN') THEN
5317
5318 ------------------------------------------------------------
5319 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
5320 ------------------------------------------------------------
5321 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5322 p_item_key,
5323 'EXPENSE_REPORT_ID');
5324
5325 DeleteExpReportFromAPTables(l_report_header_id);
5326
5327 AP_WEB_DB_VIOLATIONS_PKG.deleteViolationEntry(l_report_header_id);
5328
5329 ELSIF (p_funmode = 'CANCEL') THEN
5330 p_result := 'COMPLETE';
5331 END IF;
5332
5333 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end DeleteExpenseReport');
5334
5335 EXCEPTION
5336 WHEN OTHERS THEN
5337 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'DeleteExpenseReport',
5338 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
5339 raise;
5340 END DeleteExpenseReport;
5341
5342 ----------------------------------------------------------------
5343 PROCEDURE StartAPApprvlSubProcess(p_item_type IN VARCHAR2,
5344 p_item_key IN VARCHAR2,
5345 p_actid IN NUMBER,
5346 p_funmode IN VARCHAR2,
5347 p_result OUT NOCOPY VARCHAR2) IS
5348 -----------------------------------------------------------------
5349 l_item_key VARCHAR2(100);
5350 l_preparer_id NUMBER;
5351 l_preparer_name wf_users.name%type;
5352 l_preparer_display_name wf_users.display_name%type;
5353 l_employee_id NUMBER;
5354 l_employee_name wf_users.name%type;
5355 l_employee_display_name wf_users.display_name%type;
5356 l_report_header_id NUMBER;
5357 l_document_number VARCHAR2(50);
5358 l_emp_cost_center VARCHAR2(240);
5359 l_doc_cost_center VARCHAR2(240);
5360 l_total NUMBER;
5361 l_payment_due VARCHAR2(10) := C_IndividualPay;
5362 l_currency VARCHAR2(25);
5363 l_debug_info VARCHAR2(200);
5364 BEGIN
5365
5366 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartAPApprvlSubProcess');
5367
5368 ------------------------------------------------------------
5369 l_debug_info := 'Retrieve New Expense_Report_ID Item Attribute';
5370 ------------------------------------------------------------
5371 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5372 p_item_key,
5373 'NEW_EXPENSE_REPORT_ID');
5374
5375 --------------------------------------------------------------
5376 l_debug_info := 'Retrieve New Document Number Item Attribute';
5377 ---------------------------------------------------------------
5378 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
5379 p_item_key,
5380 'NEW_DOCUMENT_NUMBER');
5381
5382
5383 ----------------------------------------------------------------
5384 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
5385 ----------------------------------------------------------------
5386 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
5387 p_item_key,
5388 'EMP_COST_CENTER');
5389
5390 ----------------------------------------------------------------
5391 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
5392 ----------------------------------------------------------------
5393 l_doc_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
5394 p_item_key,
5395 'DOC_COST_CENTER');
5396
5397 -----------------------------------------------------
5398 l_debug_info := 'Retrieve New Total Item Attribute';
5399 -----------------------------------------------------
5400 l_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
5401 p_item_key,
5402 'NEW_TOTAL');
5403
5404 -----------------------------------------------------
5405 l_debug_info := 'Retrieve Currency Item Attribute';
5406 -----------------------------------------------------
5407 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
5408 p_item_key,
5409 'CURRENCY');
5410
5411 --------------------------------
5412 l_debug_info := 'Set item key';
5413 --------------------------------
5414 l_item_key := to_char(l_report_header_id);
5415
5416
5417 -------------------------------------------------------
5418 l_debug_info := 'Retrieve Preparer_ID Item Attribute';
5419 -------------------------------------------------------
5420 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5421 p_item_key,
5422 'PREPARER_ID');
5423
5424 -------------------------------------------------------
5425 l_debug_info := 'Retrieve Employee_ID Item Attribute';
5426 -------------------------------------------------------
5427 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5428 p_item_key,
5429 'EMPLOYEE_ID');
5430
5431 -------------------------------------------------------
5432 l_debug_info := 'Retrieve CC Payment Due From Item Attribute';
5433 -------------------------------------------------------
5434 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,
5435 p_item_key,
5436 'PAYMENT_DUE_FROM');
5437
5438 -------------------------------------------------
5439 l_debug_info := 'Create AP Approval Subprocess';
5440 -------------------------------------------------
5441 WF_ENGINE.CreateProcess(p_item_type,
5442 l_item_key,
5443 'AP_EXPENSE_REPORT_PROCESS');
5444
5445 --------------------------------------------------------
5446 l_debug_info := 'Set Expense_Report_ID Item Attribute';
5447 --------------------------------------------------------
5448 WF_ENGINE.SetItemAttrNumber(p_item_type,
5449 l_item_key,
5450 'EXPENSE_REPORT_ID',
5451 l_report_header_id);
5452
5453 ------------------------------------------------------
5454 l_debug_info := 'Set Document_Number Item Attribute';
5455 ------------------------------------------------------
5456 WF_ENGINE.SetItemAttrText(p_item_type,
5457 l_item_key,
5458 'DOCUMENT_NUMBER',
5459 l_document_number);
5460
5461 ----------------------------------------------------------
5462 l_debug_info := 'Get Preparer Name Info For Preparer_Id';
5463 ----------------------------------------------------------
5464 WF_DIRECTORY.GetUserName('PER',
5465 l_preparer_id,
5466 l_preparer_name,
5467 l_preparer_display_name);
5468
5469 WF_ENGINE.SetItemAttrText(p_item_type,
5470 l_item_key,
5471 'PREPARER_ID',
5472 l_preparer_id);
5473
5474 ----------------------------------------------------------
5475 l_debug_info := 'Set Preparer Name Info Item Attributes';
5476 ----------------------------------------------------------
5477 WF_ENGINE.SetItemAttrText(p_item_type,
5478 l_item_key,
5479 'PREPARER_NAME',
5480 l_preparer_name);
5481
5482 WF_ENGINE.SetItemAttrText(p_item_type,
5483 l_item_key,
5484 'PREPARER_DISPLAY_NAME',
5485 l_preparer_display_name);
5486
5487 ----------------------------------------------------------
5488 l_debug_info := 'Get Employee Name Info For Employee_Id';
5489 ----------------------------------------------------------
5490 WF_DIRECTORY.GetUserName('PER',
5491 l_employee_id,
5492 l_employee_name,
5493 l_employee_display_name);
5494
5495 WF_ENGINE.SetItemAttrText(p_item_type,
5496 l_item_key,
5497 'EMPLOYEE_ID',
5498 l_employee_id);
5499
5500 ----------------------------------------------------------
5501 l_debug_info := 'Set Employee Name Info Item Attributes';
5502 ----------------------------------------------------------
5503 WF_ENGINE.SetItemAttrText(p_item_type,
5504 l_item_key,
5505 'EMPLOYEE_NAME',
5506 l_employee_name);
5507
5508 WF_ENGINE.SetItemAttrText(p_item_type,
5509 l_item_key,
5510 'EMPLOYEE_DISPLAY_NAME',
5511 l_employee_display_name);
5512
5513 -------------------------------------------------
5514 l_debug_info := 'Set Total Item Attribute';
5515 -------------------------------------------------
5516 WF_ENGINE.SetItemAttrNumber(p_item_type,
5517 l_item_key,
5518 'TOTAL',
5519 l_total);
5520
5521 -----------------------------------------------------------------
5522 l_debug_info := 'Set New Adjusted Display_Total Item Attribute';
5523 -----------------------------------------------------------------
5524 WF_ENGINE.SetItemAttrText(p_item_type,
5525 l_item_key,
5526 'DISPLAY_TOTAL',
5527 to_char(l_total,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
5528
5529 ----------------------------------------------
5530 l_debug_info := 'Set Currency Item Attribute';
5531 -----------------------------------------------
5532 WF_ENGINE.SetItemAttrText(p_item_type,
5533 l_item_key,
5534 'CURRENCY',
5535 l_currency);
5536
5537
5538 -----------------------------------------------------------
5539 l_debug_info := 'Set Document Cost Center Item Attribute';
5540 -----------------------------------------------------------
5541 WF_ENGINE.SetItemAttrText(p_item_type,
5542 l_item_key,
5543 'DOC_COST_CENTER',
5544 l_doc_cost_center);
5545
5546 -----------------------------------------------------------
5547 l_debug_info := 'Set Employee Cost Center Item Attribute';
5548 -----------------------------------------------------------
5549 WF_ENGINE.SetItemAttrText(p_item_type,
5550 l_item_key,
5551 'EMP_COST_CENTER',
5552 l_emp_cost_center);
5553
5554 --------------------------------------------------------------
5555 l_debug_info := 'Set CC Payment Due From Item Attribute';
5556 --------------------------------------------------------------
5557 WF_ENGINE.SetItemAttrText(p_item_type,
5558 l_item_key,
5559 'PAYMENT_DUE_FROM',
5560 l_payment_due);
5561
5562 -----------------------------------------------------------
5563 l_debug_info := 'Skip server validation and manager approval';
5564 -----------------------------------------------------------
5565 WF_ENGINE.SetItemAttrText(p_item_type,
5566 l_item_key,
5567 'START_FROM_PROCESS',
5568 C_START_FROM_AP_APPROVAL);
5569
5570 -------------------------------------------------
5571 l_debug_info := 'Start AP Approval Sub Process';
5572 -------------------------------------------------
5573 WF_ENGINE.StartProcess(p_item_type,
5574 l_item_key);
5575
5576 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartAPApprvlSubProcess');
5577
5578 EXCEPTION
5579 WHEN OTHERS THEN
5580 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartAPApprvlSubProcess',
5581 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
5582 raise;
5583 END StartAPApprvlSubProcess;
5584
5585 ----------------------------------------------------------------------
5586 PROCEDURE StartFromAPApproval(p_item_type IN VARCHAR2,
5587 p_item_key IN VARCHAR2,
5588 p_actid IN NUMBER,
5589 p_funmode IN VARCHAR2,
5590 p_result OUT NOCOPY VARCHAR2) IS
5591 ----------------------------------------------------------------------
5592 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
5593 l_debug_info VARCHAR2(200);
5594 l_No VARCHAR2(1) := 'N';
5595 BEGIN
5596
5597 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartFromAPApproval');
5598
5599 IF (p_funmode = 'RUN') THEN
5600
5601 ----------------------------------------------------------------
5602 l_debug_info := 'Retrieve New_Expense_Report_ID Item Attribute';
5603 ----------------------------------------------------------------
5604 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5605 p_item_key,
5606 'EXPENSE_REPORT_ID');
5607
5608
5609 --------------------------------------------------------------
5610 l_debug_info := 'Update all expense lines as receipt missing';
5611 --------------------------------------------------------------
5612 -- Bug 884248
5613 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlag2(l_report_header_id)) THEN
5614 NULL;
5615 END IF;
5616
5617 ----------------------------------------------------------
5618 l_debug_info := 'Update Receipts Status to Required if Pending Resolution';
5619 ----------------------------------------------------------
5620 update ap_expense_report_headers
5621 set receipts_status = 'REQUIRED'
5622 where report_header_id = l_report_header_id
5623 and receipts_status = 'RESOLUTN';
5624
5625 ----------------------------------------------------------
5626 l_debug_info := 'Reset Receipt Missing Flag';
5627 ----------------------------------------------------------
5628 -- Bug 4075372
5629 update ap_expense_report_lines
5630 set receipt_missing_flag = l_No
5631 where report_header_id = l_report_header_id;
5632
5633 ------------------------------------------------------------
5634 l_debug_info := 'Set which process to start from';
5635 ------------------------------------------------------------
5636 -- Indicate which process to start from
5637 -- (skip ServerValidate, Manager Approval)
5638 WF_ENGINE.SetItemAttrText(p_item_type,
5639 p_item_key,
5640 'START_FROM_PROCESS',
5641 C_START_FROM_AP_APPROVAL);
5642
5643 ELSIF (p_funmode = 'CANCEL') THEN
5644 p_result := 'COMPLETE';
5645 END IF;
5646
5647 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartFromAPApproval');
5648
5649 EXCEPTION
5650 WHEN OTHERS THEN
5651 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartFromAPApproval',
5652 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
5653 raise;
5654 END StartFromAPApproval;
5655
5656 ----------------------------------------------------------------------
5657 PROCEDURE StartFromManagerApproval(p_item_type IN VARCHAR2,
5658 p_item_key IN VARCHAR2,
5659 p_actid IN NUMBER,
5660 p_funmode IN VARCHAR2,
5661 p_result OUT NOCOPY VARCHAR2) IS
5662 ----------------------------------------------------------------------
5663 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
5664 l_debug_info VARCHAR2(200);
5665 BEGIN
5666
5667 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartFromManagerApproval');
5668
5669 IF (p_funmode = 'RUN') THEN
5670
5671 ----------------------------------------------------------------
5672 l_debug_info := 'Retrieve New_Expense_Report_ID Item Attribute';
5673 ----------------------------------------------------------------
5674 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5675 p_item_key,
5676 'EXPENSE_REPORT_ID');
5677
5678
5679 --------------------------------------------------------------
5680 l_debug_info := 'Update all expense lines as receipt missing';
5681 --------------------------------------------------------------
5682 IF (NOT AP_WEB_DB_EXPLINE_PKG.SetReceiptMissing(l_report_header_id,
5683 'Y')) THEN
5684 NULL;
5685 END IF;
5686
5687 ------------------------------------------------------------
5688 l_debug_info := 'Set which process to start from';
5689 ------------------------------------------------------------
5690 -- Indicate which process to start from
5691 -- (skip ServerValidate, Manager Approval)
5692 WF_ENGINE.SetItemAttrText(p_item_type,
5693 p_item_key,
5694 'START_FROM_PROCESS',
5695 C_START_FROM_MANAGER_APPROVAL);
5696
5697 ELSIF (p_funmode = 'CANCEL') THEN
5698 p_result := 'COMPLETE';
5699 END IF;
5700
5701 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartFromManagerApproval');
5702
5703 EXCEPTION
5704 WHEN OTHERS THEN
5705 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartFromManagerApproval',
5706 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
5707 raise;
5708 END StartFromManagerApproval;
5709
5710
5711 ----------------------------------------------------------------------
5712 PROCEDURE CheckIfShortPaid(p_item_type IN VARCHAR2,
5713 p_item_key IN VARCHAR2,
5714 p_actid IN NUMBER,
5715 p_funmode IN VARCHAR2,
5716 p_result OUT NOCOPY VARCHAR2) IS
5717 ----------------------------------------------------------------------
5718 l_orig_expense_report_num VARCHAR2(50);
5719 l_debug_info VARCHAR2(200);
5720 BEGIN
5721
5722 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckIfShortPaid');
5723
5724 IF (p_funmode = 'RUN') THEN
5725
5726 ----------------------------------------------------------------
5727 l_debug_info := 'Retrieve ShortPay_Flag Item Attribute';
5728 ----------------------------------------------------------------
5729 l_orig_expense_report_num := WF_ENGINE.GetItemAttrText(p_item_type,
5730 p_item_key,
5731 'ORIG_EXPENSE_REPORT_NUM');
5732
5733 IF (l_orig_expense_report_num IS NOT NULL) THEN
5734 p_result := 'COMPLETE:Y';
5735 ELSE
5736 p_result := 'COMPLETE:N';
5737 END IF;
5738
5739 ELSIF (p_funmode = 'CANCEL') THEN
5740 p_result := 'COMPLETE';
5741 END IF;
5742
5743 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckIfShortPaid');
5744
5745 EXCEPTION
5746 WHEN OTHERS THEN
5747 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckIfShortPaid',
5748 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
5749 raise;
5750 END CheckIfShortPaid;
5751
5752
5753
5754 -----------------------------------------------------------------------------
5755 PROCEDURE BuildBothpayExpReport(p_item_type IN VARCHAR2,
5756 p_item_key IN VARCHAR2,
5757 p_actid IN NUMBER,
5758 p_funmode IN VARCHAR2,
5759 p_result OUT NOCOPY VARCHAR2)
5760 ------------------------------------------------------------------------------
5761 IS
5762 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
5763 l_total AP_WEB_DB_EXPRPT_PKG.expHdr_total := NULL;
5764 l_new_report_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
5765 l_document_number AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
5766 l_description AP_WEB_DB_EXPRPT_PKG.expHdr_description := NULL;
5767 l_vendor_id AP_WEB_DB_CCARD_PKG.cardProgs_vendorID := NULL;
5768 l_vendor_site_id AP_WEB_DB_CCARD_PKG.cardProgs_vendorSiteID := NULL;
5769 l_ccard_amt AP_WEB_DB_EXPRPT_PKG.expHdr_amtDueCcardCompany := 0;
5770 l_XpenseRec AP_WEB_DB_EXPRPT_PKG.XpenseInfoRec;
5771 l_accts_pay_comb_id AP_WEB_DB_EXPRPT_PKG.expHdr_acctsPayCodeCombID := NULL;
5772 l_debug_info VARCHAR2(2000);
5773 l_ccard_exists BOOLEAN := TRUE;
5774 l_report_submitted_date DATE;
5775 l_org_id NUMBER;
5776 l_holds_setup VARCHAR2(2);
5777 l_expense_status_code VARCHAR2(30) := NULL;
5778 BEGIN
5779
5780 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start BuildBothpayExpReport');
5781
5782 ------------------------------------------------------------
5783 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
5784 ------------------------------------------------------------
5785 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5786 p_item_key,
5787 'EXPENSE_REPORT_ID');
5788
5789 -------------------------------------------------------------------------
5790 l_debug_info := 'Retrieve and create new Document Number Item Attribute';
5791 -------------------------------------------------------------------------
5792 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
5793 p_item_key,
5794 'DOCUMENT_NUMBER') || '.1';
5795
5796
5797 -----------------------------------------------------------------
5798 l_debug_info := 'Retrieve Credit Card New Expense Report Id';
5799 -----------------------------------------------------------------
5800 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetNextExpReportID(l_new_report_id) ) THEN
5801 l_new_report_id := NULL;
5802 END IF;
5803
5804
5805 -------------------------------------------------------------------
5806 l_debug_info := 'Obtain the card number and the full name and the
5807 vendor information for the new expense report';
5808 --------------------------------------------------------------------
5809 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetExpReportInfo(l_report_header_id,
5810 l_description, l_ccard_amt, l_total)) THEN
5811 l_description := NULL;
5812 l_total := 0;
5813 l_ccard_amt := 0;
5814 l_ccard_exists := FALSE;
5815 END IF;
5816
5817 -------------------------------------------------------------------
5818 l_debug_info := 'Obtain the Vendor ID item attribute';
5819 --------------------------------------------------------------------
5820 l_vendor_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5821 p_item_key,
5822 'VENDOR_ID');
5823
5824
5825 -------------------------------------------------------------------
5826 l_debug_info := 'Obtain the Vendor Site ID item attribute';
5827 --------------------------------------------------------------------
5828 l_vendor_site_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5829 p_item_key,
5830 'VENDOR_SITE_ID');
5831
5832 /* Bug2610233 : Replacing l_ccard_amt check with l_ccard_exists check.
5833 IF (l_ccard_amt <> 0) THEN */
5834
5835 IF (l_ccard_exists = TRUE) THEN
5836 ----------------------------------------------------------------------
5837 l_debug_info := 'Get the accts pay code combination id from vendors';
5838 ----------------------------------------------------------------------
5839 IF (NOT AP_WEB_DB_AP_INT_PKG.GetVendorSitesCodeCombID(l_vendor_site_id,
5840 l_accts_pay_comb_id) OR
5841 l_accts_pay_comb_id = NULL) THEN
5842 IF (NOT AP_WEB_DB_AP_INT_PKG.GetVendorCodeCombID(l_vendor_id,
5843 l_accts_pay_comb_id)) THEN
5844 l_accts_pay_comb_id := NULL;
5845 END IF;
5846 END IF;
5847
5848
5849 /* Bug2610233 : Replacing l_ccard_amt check with l_ccard_exists check.
5850 IF (l_total - l_ccard_amt <> 0) THEN
5851 */
5852 -------------------------------------------------------------------
5853 l_debug_info := 'Create new expense report by creating new record in
5854 ap_expense_report_headers, with same info as old
5855 expense report except new id, doc number, total,
5856 bothpay parent id, paid on behalf employee id, description,
5857 and amt due ccard company';
5858 --------------------------------------------------------------------
5859 l_XpenseRec.report_header_id := l_new_report_id;
5860 l_XpenseRec.document_number := l_document_number;
5861 l_XpenseRec.employee_id := -1; --will become NULL
5862 l_XpenseRec.org_id := NULL;
5863 l_XpenseRec.vouchno := 0;
5864 l_XpenseRec.total := -1;
5865 l_XpenseRec.vendor_id := l_vendor_id;
5866 l_XpenseRec.vendor_site_id := l_vendor_site_id;
5867 l_XpenseRec.amt_due_employee := 0;
5868 l_XpenseRec.amt_due_ccard := NULL;
5869 l_XpenseRec.description := l_description;
5870 l_XpenseRec.preparer_id := NULL;
5871 l_XpenseRec.last_update_login:= NULL;
5872 l_XpenseRec.last_updated_by := NULL;
5873 l_XpenseRec.workflow_flag := NULL;
5874 l_XpenseRec.expense_check_address_flag := NULL;
5875 l_XpenseRec.bothpay_report_header_id := l_report_header_id;
5876 l_XpenseRec.shortpay_parent_id := NULL;
5877 l_XpenseRec.behalf_employee_id := -1;
5878 l_XpenseRec.approver_id := NULL;
5879 l_XpenseRec.week_end_date := NULL;
5880 l_XpenseRec.set_of_books_id := NULL;
5881 l_XpenseRec.source := 'Both Pay';
5882 l_XpenseRec.accts_pay_comb_id := l_accts_pay_comb_id;
5883
5884 ----------------------------------------------------------
5885 l_debug_info := 'Get Expense Report date';
5886 ----------------------------------------------------------
5887 select report_submitted_date
5888 into l_report_submitted_date
5889 from ap_expense_report_headers
5890 where report_header_id = l_report_header_id;
5891
5892 ------------------------------------------------------------
5893 l_debug_info := 'Retrieve ORG_ID Item Attribute';
5894 ------------------------------------------------------------
5895 l_org_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
5896 p_item_key,
5897 'ORG_ID');
5898
5899
5900 l_holds_setup := AP_WEB_HOLDS_WF.IsHoldsRuleSetup(l_org_id,
5901 l_report_submitted_date);
5902
5903 IF (l_holds_setup = 'Y') THEN
5904 l_expense_status_code := AP_WEB_RECEIPTS_WF.C_PENDING_HOLDS;
5905 ELSE
5906 l_expense_status_code := 'INVOICED';
5907 END IF;
5908
5909 l_XpenseRec.expense_status_code := l_expense_status_code;
5910
5911 IF (NOT AP_WEB_DB_EXPRPT_PKG.InsertReportHeaderLikeExisting(
5912 l_report_header_id, l_XpenseRec)) THEN
5913 NULL;
5914 END IF;
5915
5916 ------------------------------------------------------------------
5917 l_debug_info := 'Insert the lines for the credit card company into
5918 ap_expense_report_lines with new report_header_id';
5919 ------------------------------------------------------------------
5920 IF (NOT AP_WEB_DB_EXPLINE_PKG.AddCCReportLines(l_report_header_id,
5921 l_new_report_id)) THEN
5922 NULL;
5923 END IF;
5924
5925 -----------------------------------------------------------------------
5926 l_debug_info := 'Set the Bothpay Document Number Item Attribute with
5927 the new expense report document number';
5928 -----------------------------------------------------------------------
5929 WF_ENGINE.SetItemAttrText(p_item_type,
5930 p_item_key,
5931 'BOTHPAY_DOC_NUM',
5932 l_document_number);
5933
5934 --------------------------------------------------------------------
5935 l_debug_info := 'Copy Notes from original report';
5936 --------------------------------------------------------------------
5937 AP_WEB_NOTES_PKG.CopyERNotes (
5938 p_src_report_header_id => l_report_header_id,
5939 p_tgt_report_header_id => l_new_report_id
5940 );
5941
5942 END IF;
5943
5944 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end BuildBothpayExpReport');
5945
5946 EXCEPTION
5947 WHEN OTHERS THEN
5948 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'BuildBothpayReport',
5949 null, to_char(l_report_header_id) || ' ' || to_char(l_new_report_id), to_char(p_actid), l_debug_info);
5950 raise;
5951 END BuildBothpayExpReport;
5952
5953
5954 ----------------------------------------------------------------------
5955 PROCEDURE CheckIfBothpay(p_item_type IN VARCHAR2,
5956 p_item_key IN VARCHAR2,
5957 p_actid IN NUMBER,
5958 p_funmode IN VARCHAR2,
5959 p_result OUT NOCOPY VARCHAR2) IS
5960 ----------------------------------------------------------------------
5961 l_payment VARCHAR2(10);
5962 l_debug_info VARCHAR2(200);
5963
5964 BEGIN
5965
5966 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckIfBothpay');
5967
5968 IF (p_funmode = 'RUN') THEN
5969
5970
5971 ----------------------------------------------------------------
5972 l_debug_info := 'Retrieve Profile Option Payment Due From';
5973 ----------------------------------------------------------------
5974 l_payment := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
5975
5976 IF (l_payment = C_BothPay) THEN
5977 p_result := 'COMPLETE:Y';
5978 ELSE
5979 p_result := 'COMPLETE:N';
5980 END IF;
5981
5982 ELSIF (p_funmode = 'CANCEL') THEN
5983 p_result := 'COMPLETE';
5984 END IF;
5985
5986 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckIfBothpay');
5987
5988 EXCEPTION
5989 WHEN OTHERS THEN
5990 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckIfBothpay',
5991 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
5992 raise;
5993 END CheckIfBothpay;
5994
5995 ----------------------------------------------------------------------
5996 PROCEDURE FindVendor(p_item_type IN VARCHAR2,
5997 p_item_key IN VARCHAR2,
5998 p_actid IN NUMBER,
5999 p_funmode IN VARCHAR2,
6000 p_result OUT NOCOPY VARCHAR2) IS
6001 ----------------------------------------------------------------------
6002 l_debug_info VARCHAR2(200);
6003 l_vendor_id AP_WEB_DB_CCARD_PKG.cardProgs_vendorID;
6004 l_vendor_site_id AP_WEB_DB_CCARD_PKG.cardProgs_vendorID;
6005 l_report_header_id AP_WEB_DB_CCARD_PKG.ccTrxn_headerID;
6006 l_crd_card_count NUMBER := 0;
6007
6008 BEGIN
6009
6010 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start FindVendor');
6011
6012 IF (p_funmode = 'RUN') THEN
6013
6014 ----------------------------------------------------------------
6015 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
6016 ------------------------------------------------------------
6017 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6018 p_item_key,
6019 'EXPENSE_REPORT_ID');
6020
6021 ----------------------------------------------------------------
6022 l_debug_info := 'Retrieve Vendor IDs from the table';
6023 ------------------------------------------------------------
6024 IF (NOT AP_WEB_DB_CCARD_PKG.GetVendorIDs(l_report_header_id, l_vendor_id,
6025 l_vendor_site_id)) THEN
6026 l_vendor_id := NULL;
6027 l_vendor_site_id := NULL;
6028 END IF;
6029
6030 ----------------------------------------------------------------
6031 l_debug_info := 'Set the Vendor ID Attribute';
6032 ----------------------------------------------------------------
6033 WF_ENGINE.SetItemAttrNumber(p_item_type,
6034 p_item_key,
6035 'VENDOR_ID',
6036 l_vendor_id);
6037
6038 ----------------------------------------------------------------
6039 l_debug_info := 'Set the Vendor Site ID Attribute';
6040 ----------------------------------------------------------------
6041 WF_ENGINE.SetItemAttrNumber(p_item_type,
6042 p_item_key,
6043 'VENDOR_SITE_ID',
6044 l_vendor_site_id);
6045 IF (NOT AP_WEB_DB_EXPLINE_PKG.GetNumCCLinesIncluded(l_report_header_id,
6046 l_crd_card_count)) THEN
6047 l_crd_card_count := 0;
6048 END IF;
6049
6050 IF ( (l_vendor_id IS NULL OR l_vendor_site_id IS NULL)
6051 AND nvl(l_crd_card_count,0) >0 ) THEN
6052 ----------------------------------------------------------------
6053 l_debug_info := 'Get the FND message for this missing vendor';
6054 ----------------------------------------------------------------
6055 FND_MESSAGE.Set_Name('SQLAP','AP_WEB_CCARD_NO_VENDOR_INFO');
6056
6057 ----------------------------------------------------------------
6058 l_debug_info := 'Set the Error Message Attribute';
6059 ----------------------------------------------------------------
6060 WF_ENGINE.SetItemAttrText(p_item_type,
6061 p_item_key,
6062 'ERROR_MESSAGE',
6063 FND_MESSAGE.Get);
6064 p_result := 'COMPLETE:N';
6065 ELSE
6066 p_result := 'COMPLETE:Y';
6067 END IF;
6068
6069 ELSIF (p_funmode = 'CANCEL') THEN
6070 p_result := 'COMPLETE';
6071 END IF;
6072
6073 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end FindVendor');
6074
6075 EXCEPTION
6076 WHEN OTHERS THEN
6077 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'FindVendor',
6078 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
6079 raise;
6080 END FindVendor;
6081
6082
6083 ----------------------------------------------------------------------
6084 PROCEDURE CheckIfSplit(p_item_type IN VARCHAR2,
6085 p_item_key IN VARCHAR2,
6086 p_actid IN NUMBER,
6087 p_funmode IN VARCHAR2,
6088 p_result OUT NOCOPY VARCHAR2) IS
6089 ----------------------------------------------------------------------
6090 l_doc_num VARCHAR2(50);
6091 l_debug_info VARCHAR2(200);
6092 BEGIN
6093
6094 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckIfSplit');
6095
6096 IF (p_funmode = 'RUN') THEN
6097
6098 /* Bug 4096880 : The Bothpay split notification should not be
6099 * sent from OIE.J onwards. Hence, hard-code the
6100 * return value as 'N'.
6101 */
6102
6103 p_result := 'COMPLETE:N';
6104
6105 ELSIF (p_funmode = 'CANCEL') THEN
6106 p_result := 'COMPLETE';
6107 END IF;
6108
6109 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckIfSplit');
6110
6111 EXCEPTION
6112 WHEN OTHERS THEN
6113 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckIfSplit',
6114 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
6115 raise;
6116 END CheckIfSplit;
6117
6118 ----------------------------------------------------------------
6119 PROCEDURE StartPolicyShortPayProcess(p_item_type IN VARCHAR2,
6120 p_item_key IN VARCHAR2,
6121 p_actid IN NUMBER,
6122 p_funmode IN VARCHAR2,
6123 p_result OUT NOCOPY VARCHAR2) IS
6124 -----------------------------------------------------------------
6125 l_item_type VARCHAR2(100) := 'APEXP'; -- Bug 996020
6126 l_item_key VARCHAR2(100);
6127 l_preparer_id NUMBER;
6128 l_preparer_name wf_users.name%type;
6129 l_preparer_display_name wf_users.display_name%type;
6130 l_employee_id NUMBER;
6131 l_employee_name wf_users.name%type;
6132 l_employee_display_name wf_users.display_name%type;
6133 l_orig_expense_report_num VARCHAR2(50);
6134 l_report_header_id NUMBER;
6135 l_document_number VARCHAR2(50);
6136 l_emp_cost_center VARCHAR2(240);
6137 l_doc_cost_center VARCHAR2(240);
6138 l_total NUMBER;
6139 l_credit_total NUMBER;
6140 l_new_exp_total NUMBER;
6141 l_currency VARCHAR2(25);
6142 l_url VARCHAR2(1000);
6143 l_debug_info VARCHAR2(200);
6144 l_payment_due VARCHAR2(10) := C_IndividualPay;
6145
6146 l_purpose VARCHAR2(2400);
6147 l_approver_id NUMBER;
6148 l_approver_name wf_users.name%type;
6149 l_approver_display_name wf_users.display_name%type;
6150 l_submit_from_oie VARCHAR2(1);
6151
6152 C_CreditLineVersion CONSTANT NUMBER := 1;
6153 C_WF_Version NUMBER := 0;
6154
6155 -- for bug 1652106
6156 l_n_org_id NUMBER;
6157 l_n_user_id Number;
6158 l_n_resp_id Number;
6159 l_n_resp_appl_id Number;
6160
6161 -- for bug 2069362
6162 l_AMEEnabled VARCHAR2(1);
6163
6164 -- jrautiai ADJ Fix
6165 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
6166 BEGIN
6167
6168 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartPolicyShortPayProcess');
6169
6170 -----------------------------------------------------
6171 l_debug_info := 'Get Workflow Version Number 4';
6172 -----------------------------------------------------
6173 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
6174
6175 ----------------------------------
6176 l_debug_info := 'Set Org Context';
6177 ----------------------------------
6178 -- for bug 1652106
6179 begin
6180
6181 l_n_org_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6182 p_item_key,
6183 'ORG_ID');
6184 exception
6185 when others then
6186 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
6187 -- ORG_ID item attribute doesn't exist, need to add it
6188 wf_engine.AddItemAttr(p_item_type, p_item_key, 'ORG_ID');
6189 -- get the org_id from header for old reports
6190 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
6191 to_number(p_item_key),
6192 l_n_org_id) <> TRUE ) THEN
6193 l_n_org_id := NULL;
6194 END IF;
6195 WF_ENGINE.SetItemAttrNumber(p_item_type,
6196 p_item_key,
6197 'ORG_ID',
6198 l_n_org_id);
6199 else
6200 raise;
6201 end if;
6202
6203 end;
6204
6205
6206 ----------------------------------
6207 l_debug_info := 'Get User ID';
6208 ----------------------------------
6209 begin
6210 l_n_user_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6211 p_item_key,
6212 'USER_ID');
6213 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6214 p_item_key,
6215 'RESPONSIBILITY_ID');
6216 l_n_resp_appl_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6217 p_item_key,
6218 'APPLICATION_ID');
6219 exception
6220 when others then
6221 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
6222 null;
6223 else
6224 raise;
6225 end if;
6226 end;
6227
6228 ------------------------------------------------------------
6229 l_debug_info := 'Retrieve New Expense_Report_ID Item Attribute';
6230 ------------------------------------------------------------
6231 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6232 p_item_key,
6233 'POLICY_SHORTPAY_ID');
6234
6235 --------------------------------------------------------------
6236 l_debug_info := 'Retrieve New Document Number Item Attribute';
6237 ---------------------------------------------------------------
6238 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
6239 p_item_key,
6240 'POLICY_SHORTPAY_DOC_NUM');
6241
6242 --------------------------------------------------------------
6243 l_debug_info := 'Retrieve New Document Number Item Attribute';
6244 ---------------------------------------------------------------
6245 l_orig_expense_report_num := WF_ENGINE.GetItemAttrText(p_item_type,
6246 p_item_key,
6247 'DOCUMENT_NUMBER');
6248
6249
6250 ----------------------------------------------------------------
6251 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
6252 ----------------------------------------------------------------
6253 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
6254 p_item_key,
6255 'EMP_COST_CENTER');
6256
6257 ----------------------------------------------------------------
6258 l_debug_info := 'Retrieve Payment Due From Item Attribute';
6259 ----------------------------------------------------------------
6260 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
6261
6262
6263 ----------------------------------------------------------------
6264 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
6265 ----------------------------------------------------------------
6266 l_doc_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
6267 p_item_key,
6268 'DOC_COST_CENTER');
6269
6270 -----------------------------------------------------
6271 l_debug_info := 'Retrieve New Total Item Attribute';
6272 -----------------------------------------------------
6273 l_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
6274 p_item_key,
6275 'POLICY_SHORTPAY_TOTAL');
6276
6277 l_new_exp_total := l_total;
6278 l_credit_total := 0;
6279
6280 -----------------------------------------------------
6281 l_debug_info := 'Retrieve Currency Item Attribute';
6282 -----------------------------------------------------
6283 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
6284 p_item_key,
6285 'CURRENCY');
6286
6287 --------------------------------
6288 l_debug_info := 'Set item key';
6289 --------------------------------
6290 l_item_key := to_char(l_report_header_id);
6291
6292
6293 -------------------------------------------------------
6294 l_debug_info := 'Retrieve Preparer_ID Item Attribute';
6295 -------------------------------------------------------
6296 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6297 p_item_key,
6298 'PREPARER_ID');
6299
6300 -------------------------------------------------------
6301 l_debug_info := 'Retrieve Employee_ID Item Attribute';
6302 -------------------------------------------------------
6303 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6304 p_item_key,
6305 'EMPLOYEE_ID');
6306
6307 ----------------------------------
6308 l_debug_info := 'Get AME_ENABLED';
6309 ----------------------------------
6310 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
6311 p_item_key,
6312 'AME_ENABLED');
6313
6314 ----------------------------------
6315 l_debug_info := 'Get PURPOSE';
6316 ----------------------------------
6317 l_purpose := WF_ENGINE.GetItemAttrText(p_item_type,
6318 p_item_key,
6319 'PURPOSE');
6320
6321 ------------------------------------------------------------
6322 l_debug_info := 'Get Approver Info';
6323 ------------------------------------------------------------
6324 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6325 p_item_key,
6326 'APPROVER_ID');
6327
6328 l_approver_name := WF_ENGINE.GetItemAttrText(p_item_type,
6329 p_item_key,
6330 'APPROVER_NAME');
6331
6332 l_approver_display_name := WF_ENGINE.GetItemAttrText(p_item_type,
6333 p_item_key,
6334 'APPROVER_DISPLAY_NAME');
6335
6336 ----------------------------------
6337 l_debug_info := 'Get SUBMIT_FROM_OIE';
6338 ----------------------------------
6339 l_submit_from_oie := WF_ENGINE.GetItemAttrText(p_item_type,
6340 p_item_key,
6341 'SUBMIT_FROM_OIE');
6342
6343 -------------------------------------------------
6344 l_debug_info := 'Create Policy Violation Shortpay Subprocess';
6345 -------------------------------------------------
6346 WF_ENGINE.CreateProcess(p_item_type,
6347 l_item_key,
6348 'POLICY_VIOLATION_PROCESS');
6349
6350 /* Bug 2351528. Need to set the user_key for easier query */
6351 WF_ENGINE.SetItemUserKey(l_item_type,
6352 l_item_key,
6353 l_document_number);
6354
6355 ----------------------------------------------------
6356 l_debug_info := 'Set SUBMIT_FROM_OIE Item Attribute';
6357 ----------------------------------------------------
6358 WF_ENGINE.SetItemAttrText(l_item_type,
6359 l_item_key,
6360 'SUBMIT_FROM_OIE',
6361 l_submit_from_oie);
6362
6363 ------------------------------------------------------
6364 l_debug_info := 'Set PURPOSE Item Attribute';
6365 ------------------------------------------------------
6366 WF_ENGINE.SetItemAttrText(l_item_type,
6367 l_item_key,
6368 'PURPOSE',
6369 l_purpose);
6370
6371 ------------------------------------------------------
6372 l_debug_info := 'Set Approver Info';
6373 ------------------------------------------------------
6374 WF_ENGINE.SetItemAttrNumber(l_item_type,
6375 l_item_key,
6376 'APPROVER_ID',
6377 l_approver_id);
6378
6379 WF_ENGINE.SetItemAttrText(l_item_type,
6380 l_item_key,
6381 'APPROVER_NAME',
6382 l_approver_name);
6383
6384 WF_ENGINE.SetItemAttrText(l_item_type,
6385 l_item_key,
6386 'APPROVER_DISPLAY_NAME',
6387 l_approver_display_name);
6388
6389
6390 -- Bug 996020
6391 ------------------------------------------------------
6392 l_debug_info := 'Set LINE_TABLE Item Attribute';
6393 ------------------------------------------------------
6394 WF_ENGINE.SetItemAttrText(l_item_type,
6395 l_item_key,
6396 'LINE_TABLE',
6397 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key);
6398
6399 ------------------------------------------------------
6400 l_debug_info := 'Set EMP_LINE_TABLE Item Attribute';
6401 ------------------------------------------------------
6402 WF_ENGINE.SetItemAttrText(l_item_type,
6403 l_item_key,
6404 'EMP_LINE_TABLE',
6405 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key || ':'|| C_EMP);
6406
6407 --------------------------------------------------------
6408 l_debug_info := 'Set Expense_Report_ID Item Attribute';
6409 --------------------------------------------------------
6410 WF_ENGINE.SetItemAttrNumber(p_item_type,
6411 l_item_key,
6412 'EXPENSE_REPORT_ID',
6413 l_report_header_id);
6414
6415 ------------------------------------------------------
6416 l_debug_info := 'Set Document_Number Item Attribute';
6417 ------------------------------------------------------
6418 WF_ENGINE.SetItemAttrText(p_item_type,
6419 l_item_key,
6420 'DOCUMENT_NUMBER',
6421 l_document_number);
6422
6423 ------------------------------------------------------
6424 l_debug_info := 'Set Document_Number Item Attribute';
6425 ------------------------------------------------------
6426 WF_ENGINE.SetItemAttrText(p_item_type,
6427 l_item_key,
6428 'ORIG_EXPENSE_REPORT_NUM',
6429 l_orig_expense_report_num);
6430
6431 ----------------------------------------------------------
6432 l_debug_info := 'Get Preparer Name Info For Preparer_Id';
6433 ----------------------------------------------------------
6434 WF_DIRECTORY.GetUserName('PER',
6435 l_preparer_id,
6436 l_preparer_name,
6437 l_preparer_display_name);
6438
6439 WF_ENGINE.SetItemAttrText(p_item_type,
6440 l_item_key,
6441 'PREPARER_ID',
6442 l_preparer_id);
6443
6444 ----------------------------------------------------------
6445 l_debug_info := 'Set Preparer Name Info Item Attributes';
6446 ----------------------------------------------------------
6447 WF_ENGINE.SetItemAttrText(p_item_type,
6448 l_item_key,
6449 'PREPARER_NAME',
6450 l_preparer_name);
6451
6452 WF_ENGINE.SetItemAttrText(p_item_type,
6453 l_item_key,
6454 'PREPARER_DISPLAY_NAME',
6455 l_preparer_display_name);
6456
6457 ----------------------------------------------------------
6458 l_debug_info := 'Set the Owner of Workflow Process.';
6459 ----------------------------------------------------------
6460 WF_ENGINE.SetItemOwner(p_item_type, l_item_key, l_preparer_name);
6461
6462 ----------------------------------------------------------
6463 l_debug_info := 'Get Employee Name Info For Employee_Id';
6464 ----------------------------------------------------------
6465 WF_DIRECTORY.GetUserName('PER',
6466 l_employee_id,
6467 l_employee_name,
6468 l_employee_display_name);
6469
6470 WF_ENGINE.SetItemAttrText(p_item_type,
6471 l_item_key,
6472 'EMPLOYEE_ID',
6473 l_employee_id);
6474
6475 ----------------------------------------------------------
6476 l_debug_info := 'Set Employee Name Info Item Attributes';
6477 ----------------------------------------------------------
6478 WF_ENGINE.SetItemAttrText(p_item_type,
6479 l_item_key,
6480 'EMPLOYEE_NAME',
6481 l_employee_name);
6482
6483 WF_ENGINE.SetItemAttrText(p_item_type,
6484 l_item_key,
6485 'EMPLOYEE_DISPLAY_NAME',
6486 l_employee_display_name);
6487
6488 -------------------------------------------------
6489 l_debug_info := 'Set Total Item Attribute';
6490 -------------------------------------------------
6491 WF_ENGINE.SetItemAttrNumber(p_item_type,
6492 l_item_key,
6493 'TOTAL',
6494 l_total);
6495
6496 -----------------------------------------------------------------
6497 l_debug_info := 'Set New Adjusted Display_Total Item Attribute';
6498 -----------------------------------------------------------------
6499 WF_ENGINE.SetItemAttrText(p_item_type,
6500 l_item_key,
6501 'DISPLAY_TOTAL',
6502 to_char(l_total,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
6503
6504
6505
6506
6507 ---------------------------------------------------------------------------
6508 l_debug_info := 'Set Attribute value for Credit Total and New Expense Total';
6509 ---------------------------------------------------------------------------
6510
6511 IF (C_WF_Version >= C_CreditLineVersion) THEN
6512
6513 WF_ENGINE.SetItemAttrNumber(p_item_type,
6514 l_item_key,
6515 'POS_NEW_EXPENSE_TOTAL',
6516 l_new_exp_total);
6517 WF_ENGINE.SetItemAttrText(p_item_type,
6518 l_item_key,
6519 'POS_NEW_EXPENSE_DISPLAY_TOTAL',
6520 to_char(l_new_exp_total, FND_CURRENCY.Get_Format_Mask(l_currency,22)));
6521
6522 WF_ENGINE.SetItemAttrNumber(p_item_type,
6523 l_item_key,
6524 'NEG_CREDIT_TOTAL',
6525 l_credit_total);
6526 WF_ENGINE.SetItemAttrText(p_item_type,
6527 l_item_key,
6528 'NEG_CREDIT_DISPLAY_TOTAL',
6529 to_char(l_credit_total, FND_CURRENCY.Get_Format_Mask(l_currency,22)));
6530
6531
6532
6533 END IF;
6534
6535 ----------------------------------------------
6536 l_debug_info := 'Set Currency Item Attribute';
6537 -----------------------------------------------
6538 WF_ENGINE.SetItemAttrText(p_item_type,
6539 l_item_key,
6540 'CURRENCY',
6541 l_currency);
6542
6543
6544 -----------------------------------------------------------
6545 l_debug_info := 'Set Document Cost Center Item Attribute';
6546 -----------------------------------------------------------
6547 WF_ENGINE.SetItemAttrText(p_item_type,
6548 l_item_key,
6549 'DOC_COST_CENTER',
6550 l_doc_cost_center);
6551
6552 -----------------------------------------------------------
6553 l_debug_info := 'Set Employee Cost Center Item Attribute';
6554 -----------------------------------------------------------
6555 WF_ENGINE.SetItemAttrText(p_item_type,
6556 l_item_key,
6557 'EMP_COST_CENTER',
6558 l_emp_cost_center);
6559
6560 --------------------------------------------------------------
6561 l_debug_info := 'Set CC Payment Due From Item Attribute';
6562 --------------------------------------------------------------
6563 WF_ENGINE.SetItemAttrText(p_item_type,
6564 l_item_key,
6565 'PAYMENT_DUE_FROM',
6566 l_payment_due);
6567
6568 --------------------------------------------------------
6569 l_debug_info := 'Call JumpIntoFunction to retrieve URL';
6570 --------------------------------------------------------
6571 AP_WEB_INFRASTRUCTURE_PKG.JumpIntoFunction(l_report_header_id,
6572 'EXPENSE REPORT',
6573 l_url);
6574
6575 -----------------------------------------------------
6576 l_debug_info := 'Set EXPENSE DETAILS Item Attribute';
6577 -----------------------------------------------------
6578
6579 -- Be sure to clear these values. If we are resubmitting, we don't want
6580 -- the values from the previous process traversal to hang around.
6581 WF_ENGINE.SetItemAttrText(p_item_type,
6582 l_item_key,
6583 'EXPENSE_DETAILS',
6584 l_url);
6585
6586 -----------------------------------------------------
6587 l_debug_info := 'Set Org ID Item Attribute';
6588 -----------------------------------------------------
6589 begin
6590 WF_ENGINE.SetItemAttrNumber(p_item_type,
6591 l_item_key,
6592 'ORG_ID',
6593 l_n_org_id);
6594 exception
6595 when others then
6596 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
6597 -- ORG_ID item attribute doesn't exist, need to add it
6598 wf_engine.AddItemAttr(p_item_type, l_item_key, 'ORG_ID');
6599 -- get the org_id from header for old reports
6600 WF_ENGINE.SetItemAttrNumber(p_item_type,
6601 l_item_key,
6602 'ORG_ID',
6603 l_n_org_id);
6604 else
6605 raise;
6606 end if;
6607 end;
6608
6609
6610 begin
6611
6612 --------------------------------------------------------------
6613 l_debug_info := 'Set User_ID value ';
6614 --------------------------------------------------------------
6615 WF_ENGINE.SetItemAttrNumber(p_item_type,
6616 l_item_key,
6617 'USER_ID',
6618 l_n_user_id);
6619
6620
6621 --------------------------------------------------------------
6622 l_debug_info := 'Set Resp_ID value ';
6623 --------------------------------------------------------------
6624 WF_ENGINE.SetItemAttrNumber(p_item_type,
6625 l_item_key,
6626 'RESPONSIBILITY_ID',
6627 l_n_resp_id);
6628
6629 --------------------------------------------------------------
6630 l_debug_info := 'Set Resp_Appl_ID value ';
6631 --------------------------------------------------------------
6632 WF_ENGINE.SetItemAttrNumber(p_item_type,
6633 l_item_key,
6634 'APPLICATION_ID',
6635 l_n_resp_appl_id);
6636
6637 exception
6638 when others then
6639 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
6640 null;
6641 else
6642 raise;
6643 end if;
6644 end;
6645
6646 --------------------------------------------------------------
6647 l_debug_info := 'Set AME_ENABLED value ';
6648 --------------------------------------------------------------
6649 WF_ENGINE.SetItemAttrText(p_item_type,
6650 l_item_key,
6651 'AME_ENABLED',
6652 l_AMEEnabled);
6653
6654 /* jrautiai ADJ Fix Start */
6655 ----------------------------------------------------------------
6656 l_debug_info := 'Set #FROM_ROLE to AP';
6657 ----------------------------------------------------------------
6658 SetFromRoleAP(p_item_type, l_item_key, p_actid, p_funmode, p_result);
6659
6660 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_POLICY_NC_NOTE');
6661
6662 FND_MESSAGE.Set_Token('ORIG_REPORT_NUMBER', l_orig_expense_report_num);
6663 l_mess := FND_MESSAGE.GET;
6664
6665 ----------------------------------------------------------------
6666 l_debug_info := 'Set Policy Non-Compliance note';
6667 ----------------------------------------------------------------
6668 WF_ENGINE.SetItemAttrText(p_item_type,
6669 l_item_key,
6670 'WF_NOTE',
6671 l_mess);
6672
6673 /* jrautiai ADJ Fix End */
6674
6675 -------------------------------------------------
6676 l_debug_info := 'Start Policy Violation Shortpay Process';
6677 -------------------------------------------------
6678 WF_ENGINE.StartProcess(p_item_type,
6679 l_item_key);
6680 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartPolicyShortPayProcess');
6681
6682 EXCEPTION
6683 WHEN OTHERS THEN
6684 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartPolicyShortPayProcess',
6685 p_item_type, l_item_key, to_char(p_actid), l_debug_info);
6686 raise;
6687 END StartPolicyShortPayProcess;
6688
6689 ----------------------------------------------------------------
6690 PROCEDURE StartNoReceiptsShortPayProcess(p_item_type IN VARCHAR2,
6691 p_item_key IN VARCHAR2,
6692 p_actid IN NUMBER,
6693 p_funmode IN VARCHAR2,
6694 p_result OUT NOCOPY VARCHAR2) IS
6695 -----------------------------------------------------------------
6696 l_item_type VARCHAR2(100) := 'APEXP'; -- Bug 996020
6697
6698 l_item_key VARCHAR2(100);
6699 l_preparer_id NUMBER;
6700 l_preparer_name wf_users.name%type;
6701 l_preparer_display_name wf_users.display_name%type;
6702 l_employee_id NUMBER;
6703 l_employee_name wf_users.name%type;
6704 l_employee_display_name wf_users.display_name%type;
6705 l_report_header_id NUMBER;
6706 l_document_number VARCHAR2(50);
6707 l_orig_expense_report_num VARCHAR2(50);
6708 l_emp_cost_center VARCHAR2(240);
6709 l_doc_cost_center VARCHAR2(240);
6710 l_override_approver_id AP_WEB_DB_EXPRPT_PKG.expHdr_overrideApprID;
6711 l_approver_name wf_users.name%type;
6712 l_approver_display_name wf_users.display_name%type;
6713 l_total NUMBER;
6714 l_credit_total NUMBER;
6715 l_new_exp_total NUMBER;
6716 l_currency VARCHAR2(25);
6717 l_url VARCHAR2(1000);
6718 l_debug_info VARCHAR2(200);
6719 V_IsSessionProjectEnabled VARCHAR2(1);
6720 l_payment_due VARCHAR2(10) := C_IndividualPay;
6721
6722 l_purpose VARCHAR2(2400);
6723 l_approver_id NUMBER;
6724 l_submit_from_oie VARCHAR2(1);
6725
6726 C_CreditLineVersion CONSTANT NUMBER := 1;
6727 C_WF_Version NUMBER := 0;
6728
6729 -- for bug 1652106
6730 l_n_org_id NUMBER;
6731 l_n_user_id Number;
6732 l_n_resp_id Number;
6733 l_n_resp_appl_id Number;
6734
6735 -- for bug 2069362
6736 l_AMEEnabled VARCHAR2(1);
6737
6738 -- jrautiai ADJ Fix
6739 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
6740 BEGIN
6741
6742 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartNoReceiptsShortPayProcess');
6743
6744 -----------------------------------------------------
6745 l_debug_info := 'Get Workflow Version Number 5';
6746 -----------------------------------------------------
6747 C_WF_Version := GetFlowVersion(p_item_type, p_item_key);
6748
6749 ------------------------------------------------------------
6750 l_debug_info := 'Retrieve New Expense_Report_ID Item Attribute';
6751 ------------------------------------------------------------
6752 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6753 p_item_key,
6754 'NO_RECEIPTS_SHORTPAY_ID');
6755
6756 --------------------------------------------------------------
6757 l_debug_info := 'Retrieve New Document Number Item Attribute';
6758 ---------------------------------------------------------------
6759 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
6760 p_item_key,
6761 'NO_RECEIPTS_SHORTPAY_DOC_NUM');
6762
6763 --------------------------------------------------------------
6764 l_debug_info := 'Retrieve New Document Number Item Attribute';
6765 ---------------------------------------------------------------
6766 l_orig_expense_report_num := WF_ENGINE.GetItemAttrText(p_item_type,
6767 p_item_key,
6768 'DOCUMENT_NUMBER');
6769
6770 ----------------------------------------------------------------
6771 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
6772 ----------------------------------------------------------------
6773 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
6774 p_item_key,
6775 'EMP_COST_CENTER');
6776
6777 ----------------------------------------------------------------
6778 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
6779 ----------------------------------------------------------------
6780 l_doc_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
6781 p_item_key,
6782 'DOC_COST_CENTER');
6783
6784 -----------------------------------------------------
6785 l_debug_info := 'Retrieve New Total Item Attribute';
6786 -----------------------------------------------------
6787 l_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
6788 p_item_key,
6789 'NO_RECEIPTS_SHORTPAY_TOTAL');
6790
6791 l_new_exp_total := l_total;
6792 l_credit_total := 0;
6793
6794 -----------------------------------------------------
6795 l_debug_info := 'Retrieve Currency Item Attribute';
6796 -----------------------------------------------------
6797 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
6798 p_item_key,
6799 'CURRENCY');
6800
6801 --------------------------------
6802 l_debug_info := 'Set item key';
6803 --------------------------------
6804 l_item_key := to_char(l_report_header_id);
6805
6806
6807 -------------------------------------------------------
6808 l_debug_info := 'Retrieve Preparer_ID Item Attribute';
6809 -------------------------------------------------------
6810 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6811 p_item_key,
6812 'PREPARER_ID');
6813
6814 -------------------------------------------------------
6815 l_debug_info := 'Retrieve Employee_ID Item Attribute';
6816 -------------------------------------------------------
6817 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6818 p_item_key,
6819 'EMPLOYEE_ID');
6820
6821 ---------------------------------------------------------
6822 l_debug_info := 'Retrieve Payment Due From System Option';
6823 ---------------------------------------------------------
6824 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
6825
6826 ------------------------------------------------------------
6827 l_debug_info := 'Determine whether session is project enabled';
6828 ------------------------------------------------------------
6829 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_11_0_3Version) THEN
6830 V_IsSessionProjectEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
6831 p_item_key,
6832 'EMPLOYEE_PROJECT_ENABLED');
6833
6834 ELSE
6835 -- In previous versions we called
6836 -- AP_WEB_PROJECT_PKG.IsSessionProjectEnabled, but that would not work
6837 -- without having ValidateSession called. So, for older versions we
6838 -- will assume that the session is project enabled. Since the receipts
6839 -- will not have any project information, the patc call will not be done.
6840 V_IsSessionProjectEnabled := 'Y';
6841 END IF;
6842
6843
6844 ----------------------------------
6845 l_debug_info := 'Set Org Context';
6846 ----------------------------------
6847 -- for bug 1652106
6848 begin
6849
6850 l_n_org_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6851 p_item_key,
6852 'ORG_ID');
6853 exception
6854 when others then
6855 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
6856 -- ORG_ID item attribute doesn't exist, need to add it
6857 wf_engine.AddItemAttr(p_item_type, p_item_key, 'ORG_ID');
6858 -- get the org_id from header for old reports
6859 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
6860 to_number(p_item_key),
6861 l_n_org_id) <> TRUE ) THEN
6862 l_n_org_id := NULL;
6863 END IF;
6864 WF_ENGINE.SetItemAttrText(p_item_type,
6865 p_item_key,
6866 'ORG_ID',
6867 l_n_org_id);
6868 else
6869 raise;
6870 end if;
6871
6872 end;
6873
6874 ----------------------------------
6875 l_debug_info := 'Get User ID';
6876 ----------------------------------
6877 begin
6878 l_n_user_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6879 p_item_key,
6880 'USER_ID');
6881 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6882 p_item_key,
6883 'RESPONSIBILITY_ID');
6884 l_n_resp_appl_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6885 p_item_key,
6886 'APPLICATION_ID');
6887 exception
6888 when others then
6889 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
6890 null;
6891 else
6892 raise;
6893 end if;
6894 end;
6895
6896 ----------------------------------
6897 l_debug_info := 'Get AME_ENABLED';
6898 ----------------------------------
6899 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
6900 p_item_key,
6901 'AME_ENABLED');
6902
6903 ----------------------------------
6904 l_debug_info := 'Get PURPOSE';
6905 ----------------------------------
6906 l_purpose := WF_ENGINE.GetItemAttrText(p_item_type,
6907 p_item_key,
6908 'PURPOSE');
6909
6910 ------------------------------------------------------------
6911 l_debug_info := 'Get Approver Info';
6912 ------------------------------------------------------------
6913 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
6914 p_item_key,
6915 'APPROVER_ID');
6916
6917 l_approver_name := WF_ENGINE.GetItemAttrText(p_item_type,
6918 p_item_key,
6919 'APPROVER_NAME');
6920
6921 l_approver_display_name := WF_ENGINE.GetItemAttrText(p_item_type,
6922 p_item_key,
6923 'APPROVER_DISPLAY_NAME');
6924
6925 ----------------------------------
6926 l_debug_info := 'Get SUBMIT_FROM_OIE';
6927 ----------------------------------
6928 l_submit_from_oie := WF_ENGINE.GetItemAttrText(p_item_type,
6929 p_item_key,
6930 'SUBMIT_FROM_OIE');
6931
6932 -------------------------------------------------
6933 l_debug_info := 'Create Missing Receipts Shortpay Subprocess';
6934 -------------------------------------------------
6935 WF_ENGINE.CreateProcess(p_item_type,
6936 l_item_key,
6937 'NO_RECEIPTS_SHORTPAY_PROCESS');
6938
6939 /* Bug 2351528. Need to set the user_key for easier query */
6940 WF_ENGINE.SetItemUserKey(l_item_type,
6941 l_item_key,
6942 l_document_number);
6943
6944 ----------------------------------------------------
6945 l_debug_info := 'Set SUBMIT_FROM_OIE Item Attribute';
6946 ----------------------------------------------------
6947 WF_ENGINE.SetItemAttrText(l_item_type,
6948 l_item_key,
6949 'SUBMIT_FROM_OIE',
6950 l_submit_from_oie);
6951
6952 ------------------------------------------------------
6953 l_debug_info := 'Set PURPOSE Item Attribute';
6954 ------------------------------------------------------
6955 WF_ENGINE.SetItemAttrText(l_item_type,
6956 l_item_key,
6957 'PURPOSE',
6958 l_purpose);
6959
6960 ------------------------------------------------------
6961 l_debug_info := 'Set Approver Info';
6962 ------------------------------------------------------
6963 WF_ENGINE.SetItemAttrNumber(l_item_type,
6964 l_item_key,
6965 'APPROVER_ID',
6966 l_approver_id);
6967
6968 WF_ENGINE.SetItemAttrText(l_item_type,
6969 l_item_key,
6970 'APPROVER_NAME',
6971 l_approver_name);
6972
6973 WF_ENGINE.SetItemAttrText(l_item_type,
6974 l_item_key,
6975 'APPROVER_DISPLAY_NAME',
6976 l_approver_display_name);
6977
6978 -- Bug 996020
6979 ------------------------------------------------------
6980 l_debug_info := 'Set LINE_TABLE Item Attribute';
6981 ------------------------------------------------------
6982 WF_ENGINE.SetItemAttrText(l_item_type,
6983 l_item_key,
6984 'LINE_TABLE',
6985 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key);
6986
6987 ------------------------------------------------------
6988 l_debug_info := 'Set EMP_LINE_TABLE Item Attribute';
6989 ------------------------------------------------------
6990 WF_ENGINE.SetItemAttrText(l_item_type,
6991 l_item_key,
6992 'EMP_LINE_TABLE',
6993 'plsqlclob:AP_WEB_EXPENSE_WF.generateExpClobLines/'||l_item_type||':'||l_item_key || ':'||C_EMP);
6994
6995 --------------------------------------------------------
6996 l_debug_info := 'Set Expense_Report_ID Item Attribute';
6997 --------------------------------------------------------
6998 WF_ENGINE.SetItemAttrNumber(p_item_type,
6999 l_item_key,
7000 'EXPENSE_REPORT_ID',
7001 l_report_header_id);
7002
7003 ------------------------------------------------------
7004 l_debug_info := 'Set Document_Number Item Attribute';
7005 ------------------------------------------------------
7006 WF_ENGINE.SetItemAttrText(p_item_type,
7007 l_item_key,
7008 'DOCUMENT_NUMBER',
7009 l_document_number);
7010
7011 ------------------------------------------------------
7012 l_debug_info := 'Set Document_Number Item Attribute';
7013 ------------------------------------------------------
7014 WF_ENGINE.SetItemAttrText(p_item_type,
7015 l_item_key,
7016 'ORIG_EXPENSE_REPORT_NUM',
7017 l_orig_expense_report_num);
7018
7019 ----------------------------------------------------------
7020 l_debug_info := 'Get Preparer Name Info For Preparer_Id';
7021 ----------------------------------------------------------
7022 WF_DIRECTORY.GetUserName('PER',
7023 l_preparer_id,
7024 l_preparer_name,
7025 l_preparer_display_name);
7026
7027 WF_ENGINE.SetItemAttrText(p_item_type,
7028 l_item_key,
7029 'PREPARER_ID',
7030 l_preparer_id);
7031
7032 ----------------------------------------------------------
7033 l_debug_info := 'Set Preparer Name Info Item Attributes';
7034 ----------------------------------------------------------
7035 WF_ENGINE.SetItemAttrText(p_item_type,
7036 l_item_key,
7037 'PREPARER_NAME',
7038 l_preparer_name);
7039
7040 WF_ENGINE.SetItemAttrText(p_item_type,
7041 l_item_key,
7042 'PREPARER_DISPLAY_NAME',
7043 l_preparer_display_name);
7044
7045 ----------------------------------------------------------
7046 l_debug_info := 'Set the Owner of Workflow Process.';
7047 ----------------------------------------------------------
7048 WF_ENGINE.SetItemOwner(p_item_type, l_item_key, l_preparer_name);
7049
7050 ----------------------------------------------------------
7051 l_debug_info := 'Get Employee Name Info For Employee_Id';
7052 ----------------------------------------------------------
7053 WF_DIRECTORY.GetUserName('PER',
7054 l_employee_id,
7055 l_employee_name,
7056 l_employee_display_name);
7057
7058 WF_ENGINE.SetItemAttrText(p_item_type,
7059 l_item_key,
7060 'EMPLOYEE_ID',
7061 l_employee_id);
7062
7063 ----------------------------------------------------------
7064 l_debug_info := 'Set Employee Name Info Item Attributes';
7065 ----------------------------------------------------------
7066 WF_ENGINE.SetItemAttrText(p_item_type,
7067 l_item_key,
7068 'EMPLOYEE_NAME',
7069 l_employee_name);
7070
7071 WF_ENGINE.SetItemAttrText(p_item_type,
7072 l_item_key,
7073 'EMPLOYEE_DISPLAY_NAME',
7074 l_employee_display_name);
7075
7076 -------------------------------------------------
7077 l_debug_info := 'Set Total Item Attribute';
7078 -------------------------------------------------
7079 WF_ENGINE.SetItemAttrNumber(p_item_type,
7080 l_item_key,
7081 'TOTAL',
7082 l_total);
7083
7084 -----------------------------------------------------------------
7085 l_debug_info := 'Set New Adjusted Display_Total Item Attribute';
7086 -----------------------------------------------------------------
7087 WF_ENGINE.SetItemAttrText(p_item_type,
7088 l_item_key,
7089 'DISPLAY_TOTAL',
7090 to_char(l_total,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
7091
7092 --------------------------------------------------------------
7093 l_debug_info := 'Set CC Payment Due From Item Attribute';
7094 --------------------------------------------------------------
7095 WF_ENGINE.SetItemAttrText(p_item_type,
7096 l_item_key,
7097 'PAYMENT_DUE_FROM',
7098 l_payment_due);
7099
7100 ---------------------------------------------------------------------------
7101 l_debug_info := 'Set Attribute value for Credit Total and New Expense Total';
7102 ---------------------------------------------------------------------------
7103
7104 IF (C_WF_Version >= C_CreditLineVersion) THEN
7105
7106 WF_ENGINE.SetItemAttrNumber(p_item_type,
7107 l_item_key,
7108 'POS_NEW_EXPENSE_TOTAL',
7109 l_new_exp_total);
7110 WF_ENGINE.SetItemAttrText(p_item_type,
7111 l_item_key,
7112 'POS_NEW_EXPENSE_DISPLAY_TOTAL',
7113 to_char(l_new_exp_total, FND_CURRENCY.Get_Format_Mask(l_currency,22)));
7114
7115 WF_ENGINE.SetItemAttrNumber(p_item_type,
7116 l_item_key,
7117 'NEG_CREDIT_TOTAL',
7118 l_credit_total);
7119 WF_ENGINE.SetItemAttrText(p_item_type,
7120 l_item_key,
7121 'NEG_CREDIT_DISPLAY_TOTAL',
7122 to_char(l_credit_total, FND_CURRENCY.Get_Format_Mask(l_currency,22)));
7123
7124 END IF;
7125
7126 ---------------------------------------------------------------------------
7127 l_debug_info := 'Set whether employee is project enabled';
7128 ---------------------------------------------------------------------------
7129 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_11_0_3Version) THEN
7130
7131 WF_ENGINE.SetItemAttrText(p_item_type,
7132 l_item_key,
7133 'EMPLOYEE_PROJECT_ENABLED',
7134 V_IsSessionProjectEnabled);
7135 END IF;
7136
7137
7138 ----------------------------------------------
7139 l_debug_info := 'Set Currency Item Attribute';
7140 -----------------------------------------------
7141 WF_ENGINE.SetItemAttrText(p_item_type,
7142 l_item_key,
7143 'CURRENCY',
7144 l_currency);
7145
7146
7147 -----------------------------------------------------------
7148 l_debug_info := 'Set Document Cost Center Item Attribute';
7149 -----------------------------------------------------------
7150 WF_ENGINE.SetItemAttrText(p_item_type,
7151 l_item_key,
7152 'DOC_COST_CENTER',
7153 l_doc_cost_center);
7154
7155 -----------------------------------------------------------
7156 l_debug_info := 'Set Employee Cost Center Item Attribute';
7157 -----------------------------------------------------------
7158 WF_ENGINE.SetItemAttrText(p_item_type,
7159 l_item_key,
7160 'EMP_COST_CENTER',
7161 l_emp_cost_center);
7162
7163 --------------------------------------------------------
7164 l_debug_info := 'Call JumpIntoFunction to retrieve URL';
7165 --------------------------------------------------------
7166 AP_WEB_INFRASTRUCTURE_PKG.JumpIntoFunction(l_report_header_id,
7167 'EXPENSE REPORT',
7168 l_url);
7169
7170 -----------------------------------------------------
7171 l_debug_info := 'Set EXPENSE DETAILS Item Attribute';
7172 -----------------------------------------------------
7173
7174 -- Be sure to clear these values. If we are resubmitting, we don't want
7175 -- the values from the previous process traversal to hang around.
7176 WF_ENGINE.SetItemAttrText(p_item_type,
7177 l_item_key,
7178 'EXPENSE_DETAILS',
7179 l_url);
7180
7181
7182 IF (AP_WEB_DB_EXPRPT_PKG.GetOverrideApproverID(to_number(l_item_key),
7183 l_override_approver_id)) THEN
7184
7185 WF_DIRECTORY.GetUserName('PER',
7186 l_override_approver_id,
7187 l_approver_name,
7188 l_approver_display_name);
7189
7190 WF_ENGINE.SetItemAttrNumber(p_item_type,
7191 l_item_key,
7192 'APPROVER_ID',
7193 l_override_approver_id);
7194
7195 WF_ENGINE.SetItemAttrText(p_item_type,
7196 l_item_key,
7197 'APPROVER_NAME',
7198 l_approver_name);
7199
7200 WF_ENGINE.SetItemAttrText(p_item_type,
7201 l_item_key,
7202 'APPROVER_DISPLAY_NAME',
7203 l_approver_display_name);
7204
7205 END IF;
7206
7207 -----------------------------------------------------
7208 l_debug_info := 'Set Org ID Item Attribute';
7209 -----------------------------------------------------
7210 begin
7211 WF_ENGINE.SetItemAttrNumber(p_item_type,
7212 l_item_key,
7213 'ORG_ID',
7214 l_n_org_id);
7215 exception
7216 when others then
7217 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
7218 -- ORG_ID item attribute doesn't exist, need to add it
7219 wf_engine.AddItemAttr(p_item_type, l_item_key, 'ORG_ID');
7220 -- get the org_id from header for old reports
7221 WF_ENGINE.SetItemAttrNumber(p_item_type,
7222 l_item_key,
7223 'ORG_ID',
7224 l_n_org_id);
7225 else
7226 raise;
7227 end if;
7228 end;
7229
7230 begin
7231
7232 --------------------------------------------------------------
7233 l_debug_info := 'Set User_ID value ';
7234 --------------------------------------------------------------
7235 WF_ENGINE.SetItemAttrNumber(p_item_type,
7236 l_item_key,
7237 'USER_ID',
7238 l_n_user_id);
7239
7240
7241 --------------------------------------------------------------
7242 l_debug_info := 'Set Resp_ID value ';
7243 --------------------------------------------------------------
7244 WF_ENGINE.SetItemAttrNumber(p_item_type,
7245 l_item_key,
7246 'RESPONSIBILITY_ID',
7247 l_n_resp_id);
7248
7249 --------------------------------------------------------------
7250 l_debug_info := 'Set Resp_Appl_ID value ';
7251 --------------------------------------------------------------
7252 WF_ENGINE.SetItemAttrNumber(p_item_type,
7253 l_item_key,
7254 'APPLICATION_ID',
7255 l_n_resp_appl_id);
7256
7257 exception
7258 when others then
7259 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
7260 null;
7261 else
7262 raise;
7263 end if;
7264 end;
7265
7266 --------------------------------------------------------------
7267 l_debug_info := 'Set AME_ENABLED value ';
7268 --------------------------------------------------------------
7269 WF_ENGINE.SetItemAttrText(p_item_type,
7270 l_item_key,
7271 'AME_ENABLED',
7272 l_AMEEnabled);
7273
7274 /* jrautiai ADJ Fix Start */
7275
7276 ----------------------------------------------------------------
7277 l_debug_info := 'Set #FROM_ROLE to AP';
7278 ----------------------------------------------------------------
7279 SetFromRoleAP(p_item_type, l_item_key, p_actid, p_funmode, p_result);
7280
7281 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_POLICY_MR_NOTE');
7282
7283 FND_MESSAGE.Set_Token('ORIG_REPORT_NUMBER', l_orig_expense_report_num);
7284 l_mess := FND_MESSAGE.GET;
7285
7286 ----------------------------------------------------------------
7287 l_debug_info := 'Set Missing receipts note';
7288 ----------------------------------------------------------------
7289 WF_ENGINE.SetItemAttrText(p_item_type,
7290 l_item_key,
7291 'WF_NOTE',
7292 l_mess);
7293
7294 /* jrautiai ADJ Fix End */
7295
7296 -------------------------------------------------------
7297 l_debug_info := 'Start No Receipts Short Pay Process';
7298 -------------------------------------------------------
7299 WF_ENGINE.StartProcess(p_item_type,
7300 l_item_key);
7301
7302
7303 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartNoReceiptsShortPayProcess');
7304
7305 EXCEPTION
7306 WHEN OTHERS THEN
7307 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartNoReceiptsShortPayProcess',
7308 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
7309 raise;
7310 END StartNoReceiptsShortPayProcess;
7311
7312 ---------------------------------------------------------------------
7313 PROCEDURE StartManagerApprvlSubProcess(p_item_type IN VARCHAR2,
7314 p_item_key IN VARCHAR2,
7315 p_actid IN NUMBER,
7316 p_funmode IN VARCHAR2,
7317 p_result OUT NOCOPY VARCHAR2) IS
7318 ---------------------------------------------------------------------
7319 l_item_key VARCHAR2(100);
7320 l_preparer_id NUMBER;
7321 l_preparer_name wf_users.name%type;
7322 l_preparer_display_name wf_users.display_name%type;
7323 l_employee_id NUMBER;
7324 l_employee_name wf_users.name%type;
7325 l_employee_display_name wf_users.display_name%type;
7326 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
7327 l_document_number VARCHAR2(50);
7328 l_total NUMBER;
7329 l_emp_cost_center VARCHAR2(240);
7330 l_doc_cost_center VARCHAR2(240);
7331 l_currency VARCHAR2(50);
7332 l_week_end_date DATE;
7333 l_debug_info VARCHAR2(200);
7334 l_payment_due VARCHAR2(10) := C_IndividualPay;
7335
7336 C_WF_VERSION NUMBER;
7337
7338 BEGIN
7339
7340 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StartManagerApprvlSubProcess');
7341
7342 ----------------------------------------------------------------
7343 l_debug_info := 'Get the version of the workflow currently using';
7344 ----------------------------------------------------------------
7345 C_WF_VERSION := GetFlowVersion(p_item_type, p_item_key);
7346
7347 ----------------------------------------------------------------
7348 l_debug_info := 'Retrieve New_Expense_Report_ID Item Attribute';
7349 ----------------------------------------------------------------
7350 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7351 p_item_key,
7352 'NEW_EXPENSE_REPORT_ID');
7353
7354
7355 --------------------------------------------------------------
7356 l_debug_info := 'Update all expense lines as receipt missing';
7357 --------------------------------------------------------------
7358 IF (NOT AP_WEB_DB_EXPLINE_PKG.SetReceiptMissing(l_report_header_id,
7359 'Y')) THEN
7360 NULL;
7361 END IF;
7362
7363 --------------------------------------------------------------
7364 l_debug_info := 'Retrieve New_Document_Number Item Attribute';
7365 --------------------------------------------------------------
7366 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
7367 p_item_key,
7368 'NEW_DOCUMENT_NUMBER');
7369
7370 -----------------------------------------------------
7371 l_debug_info := 'Retrieve New_Total Item Attribute';
7372 -----------------------------------------------------
7373 l_total := WF_ENGINE.GetItemAttrNumber(p_item_type,
7374 p_item_key,
7375 'NEW_TOTAL');
7376
7377 -----------------------------------------------------
7378 l_debug_info := 'Retrieve Currency Item Attribute';
7379 -----------------------------------------------------
7380 l_currency := WF_ENGINE.GetItemAttrText(p_item_type,
7381 p_item_key,
7382 'CURRENCY');
7383
7384 --------------------------------
7385 l_debug_info := 'Set Item Key';
7386 --------------------------------
7387 l_item_key := to_char(l_report_header_id);
7388
7389 -------------------------------------------------------
7390 l_debug_info := 'Retrieve Preparer_Id Item Attribute';
7391 -------------------------------------------------------
7392 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7393 p_item_key,
7394 'PREPARER_ID');
7395
7396 -------------------------------------------------------
7397 l_debug_info := 'Retrieve Employee_Id Item Attribute';
7398 -------------------------------------------------------
7399 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7400 p_item_key,
7401 'EMPLOYEE_ID');
7402
7403 ----------------------------------------------------------------
7404 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
7405 ----------------------------------------------------------------
7406 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
7407 p_item_key,
7408 'EMP_COST_CENTER');
7409
7410 ----------------------------------------------------------------
7411 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
7412 ----------------------------------------------------------------
7413 l_doc_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
7414 p_item_key,
7415 'DOC_COST_CENTER');
7416
7417 ---------------------------------------------------------
7418 l_debug_info := 'Retrieve Payment Due From System Option';
7419 ---------------------------------------------------------
7420 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
7421
7422 -----------------------------------------
7423 l_debug_info := 'Retrieve Week End Date';
7424 -----------------------------------------
7425 IF (C_WF_Version >= C_ProjectIntegrationVersion) THEN
7426
7427 l_week_end_date := WF_ENGINE.GetItemAttrDate(p_item_type,
7428 p_item_key,
7429 'WEEK_END_DATE');
7430
7431 END IF;
7432
7433 ------------------------------------------------------------
7434 l_debug_info := 'Create Approval Subprocess';
7435 ------------------------------------------------------------
7436 WF_ENGINE.CreateProcess(p_item_type,
7437 l_item_key,
7438 'AP_EXPENSE_REPORT_PROCESS');
7439
7440 --------------------------------------------------------
7441 l_debug_info := 'Set Expense_Report_ID Item Attribute';
7442 --------------------------------------------------------
7443 WF_ENGINE.SetItemAttrNumber(p_item_type,
7444 l_item_key,
7445 'EXPENSE_REPORT_ID',
7446 l_report_header_id);
7447
7448 ----------------------------------------------------------
7449 l_debug_info := 'Set Document_Number Item Attribute';
7450 ----------------------------------------------------------
7451 WF_ENGINE.SetItemAttrText(p_item_type,
7452 l_item_key,
7453 'DOCUMENT_NUMBER',
7454 l_document_number);
7455
7456 --------------------------------------------------------------------
7457 l_debug_info := 'Retrieve Preparer_Name Info for given preparer_id';
7458 --------------------------------------------------------------------
7459 WF_DIRECTORY.GetUserName('PER',
7460 l_preparer_id,
7461 l_preparer_name,
7462 l_preparer_display_name);
7463
7464 --------------------------------------------------
7465 l_debug_info := 'Set Preparer_ID Item Attribute';
7466 --------------------------------------------------
7467 WF_ENGINE.SetItemAttrText(p_item_type,
7468 l_item_key,
7469 'PREPARER_ID',
7470 l_preparer_id);
7471
7472 ---------------------------------------------------------
7473 l_debug_info := 'Set Preparer_Name Info Item Attributes';
7474 ---------------------------------------------------------
7475 WF_ENGINE.SetItemAttrText(p_item_type,
7476 l_item_key,
7477 'PREPARER_NAME',
7478 l_preparer_name);
7479
7480 WF_ENGINE.SetItemAttrText(p_item_type,
7481 l_item_key,
7482 'PREPARER_DISPLAY_NAME',
7483 l_preparer_display_name);
7484
7485 --------------------------------------------------------------------
7486 l_debug_info := 'Retrieve Employee_Name Info for given Employee_id';
7487 --------------------------------------------------------------------
7488 WF_DIRECTORY.GetUserName('PER',
7489 l_employee_id,
7490 l_employee_name,
7491 l_employee_display_name);
7492
7493 --------------------------------------------------
7494 l_debug_info := 'Set Employee_ID Item Attribute';
7495 --------------------------------------------------
7496 WF_ENGINE.SetItemAttrText(p_item_type,
7497 l_item_key,
7498 'EMPLOYEE_ID',
7499 l_employee_id);
7500
7501 ---------------------------------------------------------
7502 l_debug_info := 'Set Employee_Name Info Item Attributes';
7503 ---------------------------------------------------------
7504 WF_ENGINE.SetItemAttrText(p_item_type,
7505 l_item_key,
7506 'EMPLOYEE_NAME',
7507 l_employee_name);
7508
7509 WF_ENGINE.SetItemAttrText(p_item_type,
7510 l_item_key,
7511 'EMPLOYEE_DISPLAY_NAME',
7512 l_employee_display_name);
7513
7514 ------------------------------------------------------------
7515 l_debug_info := 'Set Total Item Attribute';
7516 ------------------------------------------------------------
7517 WF_ENGINE.SetItemAttrNumber(p_item_type,
7518 l_item_key,
7519 'TOTAL',
7520 l_total);
7521
7522
7523 -----------------------------------------------------------------
7524 l_debug_info := 'Set New Adjusted Display_Total Item Attribute';
7525 -----------------------------------------------------------------
7526 WF_ENGINE.SetItemAttrText(p_item_type,
7527 l_item_key,
7528 'DISPLAY_TOTAL',
7529 to_char(l_total,FND_CURRENCY.Get_Format_Mask(l_currency,22)) || ' ' || l_currency);
7530
7531 ----------------------------------------------
7532 l_debug_info := 'Set Currency Item Attribute';
7533 -----------------------------------------------
7534 WF_ENGINE.SetItemAttrText(p_item_type,
7535 l_item_key,
7536 'CURRENCY',
7537 l_currency);
7538
7539
7540 -----------------------------------------------------------
7541 l_debug_info := 'Set Document Cost Center Item Attribute';
7542 -----------------------------------------------------------
7543 WF_ENGINE.SetItemAttrText(p_item_type,
7544 l_item_key,
7545 'DOC_COST_CENTER',
7546 l_doc_cost_center);
7547
7548 -----------------------------------------------------------
7549 l_debug_info := 'Set Employee Cost Center Item Attribute';
7550 -----------------------------------------------------------
7551 WF_ENGINE.SetItemAttrText(p_item_type,
7552 l_item_key,
7553 'EMP_COST_CENTER',
7554 l_emp_cost_center);
7555
7556 --------------------------------------------------------------
7557 l_debug_info := 'Set CC Payment Due From Item Attribute';
7558 --------------------------------------------------------------
7559 WF_ENGINE.SetItemAttrText(p_item_type,
7560 l_item_key,
7561 'PAYMENT_DUE_FROM',
7562 l_payment_due);
7563
7564 IF (C_WF_Version >= C_ProjectIntegrationVersion) THEN
7565
7566 -------------------------------------------------
7567 l_debug_info := 'Set Week End Date used in determining PA auto approval';
7568 -------------------------------------------------
7569 WF_ENGINE.SetItemAttrDate(p_item_type,
7570 l_item_key,
7571 'WEEK_END_DATE',
7572 l_week_end_date);
7573
7574 END IF;
7575
7576 -----------------------------------------------------------
7577 l_debug_info := 'Skip server validation';
7578 -----------------------------------------------------------
7579 WF_ENGINE.SetItemAttrText(p_item_type,
7580 l_item_key,
7581 'START_FROM_PROCESS',
7582 C_START_FROM_MANAGER_APPROVAL);
7583
7584 ------------------------------------------------------
7585 l_debug_info := 'Start Manager Approval Sub Process';
7586 ------------------------------------------------------
7587 WF_ENGINE.StartProcess(p_item_type,
7588 l_item_key);
7589
7590 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StartManagerApprvlSubProcess');
7591
7592 EXCEPTION
7593 WHEN OTHERS THEN
7594 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StartManagerApprvlSubProcess',
7595 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
7596 raise;
7597 END StartManagerApprvlSubProcess;
7598
7599 -------------------------------------------------------
7600 PROCEDURE GetManager(p_employee_id IN HR_EMPLOYEES_CURRENT_V.employee_id%TYPE,
7601 p_manager_id OUT NOCOPY HR_EMPLOYEES_CURRENT_V.employee_id%TYPE) IS
7602 -------------------------------------------------------
7603 l_debug_info VARCHAR2(200);
7604 BEGIN
7605
7606 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetManager');
7607
7608 -------------------------------------------------------
7609 l_debug_info := 'Trying to retrieve employee manager';
7610 -------------------------------------------------------
7611 IF (NOT AP_WEB_DB_HR_INT_PKG.GetSupervisorID(p_employee_id, p_manager_id)) THEN
7612 p_manager_id := NULL;
7613 END IF;
7614
7615 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetManager');
7616
7617 EXCEPTION
7618 WHEN OTHERS THEN
7619 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetManager',
7620 null, null, null, l_debug_info);
7621 raise;
7622 END GetManager;
7623
7624 --------------------------------------------------------
7625 PROCEDURE SetPersonAs(p_manager_id IN NUMBER,
7626 p_item_type IN VARCHAR2,
7627 p_item_key IN VARCHAR2,
7628 p_manager_target IN VARCHAR2) IS
7629 --------------------------------------------------------
7630 l_manager_name wf_users.name%type;
7631 l_manager_display_name wf_users.display_name%type;
7632 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
7633 l_debug_info VARCHAR2(200);
7634 BEGIN
7635
7636 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetPersonAs');
7637
7638 ------------------------------------------------------------
7639 l_debug_info := 'Retrieve Manager_Name Info for Manager_Id';
7640 ------------------------------------------------------------
7641 WF_DIRECTORY.GetUserName('PER',
7642 p_manager_id,
7643 l_manager_name,
7644 l_manager_display_name);
7645
7646 IF (p_manager_target = 'MANAGER') THEN
7647
7648 WF_ENGINE.SetItemAttrText(p_item_type,
7649 p_item_key,
7650 'MANAGER_ID',
7651 p_manager_id);
7652
7653 --------------------------------------------------------
7654 l_debug_info := 'Set Manager_Name Info Item Attribute';
7655 --------------------------------------------------------
7656 WF_ENGINE.SetItemAttrText(p_item_type,
7657 p_item_key,
7658 'MANAGER_NAME',
7659 l_manager_name);
7660
7661 ---------------------------------------------------------------
7662 l_debug_info := 'Set Manager_Display_Name Info Item Attribute';
7663 ---------------------------------------------------------------
7664 WF_ENGINE.SetItemAttrText(p_item_type,
7665 p_item_key,
7666 'MANAGER_DISPLAY_NAME',
7667 l_manager_display_name);
7668
7669 ELSE
7670
7671 --------------------------------------------------------
7672 l_debug_info := 'Set Approver_ID Info Item Attribute';
7673 --------------------------------------------------------
7674 WF_ENGINE.SetItemAttrText(p_item_type,
7675 p_item_key,
7676 'APPROVER_ID',
7677 p_manager_id);
7678
7679 --------------------------------------------------------
7680 l_debug_info := 'Set Approver_Name Info Item Attribute';
7681 --------------------------------------------------------
7682 WF_ENGINE.SetItemAttrText(p_item_type,
7683 p_item_key,
7684 'APPROVER_NAME',
7685 l_manager_name);
7686
7687 ----------------------------------------------------------------
7688 l_debug_info := 'Set Approver_Display_Name Info Item Attribute';
7689 ----------------------------------------------------------------
7690 WF_ENGINE.SetItemAttrText(p_item_type,
7691 p_item_key,
7692 'APPROVER_DISPLAY_NAME',
7693 l_manager_display_name);
7694
7695 ----------------------------------------------------------------
7696 l_debug_info := 'Retrieving EXPENSE_REPORT_ID Item Attribute';
7697 ----------------------------------------------------------------
7698 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7699 p_item_key,
7700 'EXPENSE_REPORT_ID');
7701 /* Bug 3566496: Need to update expense_current_approver_id since that
7702 * is used to display the approver in the Track expenses page.
7703 */
7704
7705 UPDATE ap_expense_report_headers_all
7706 SET expense_current_approver_id = p_manager_id
7707 WHERE report_header_id = l_report_header_id;
7708
7709 END IF;
7710
7711 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetPersonAs');
7712
7713 EXCEPTION
7714 WHEN OTHERS THEN
7715 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetPersonAs',
7716 p_item_type, p_item_key, null, l_debug_info);
7717 raise;
7718 END SetPersonAs;
7719
7720 -- 3257576 added new parameters p_error_message, p_instructions,
7721 -- p_special_instr
7722 ---------------------------------------------------------------------------
7723 PROCEDURE GetFinalApprover(p_employee_id IN NUMBER,
7724 p_override_approver_id IN NUMBER,
7725 p_emp_cost_center IN VARCHAR2,
7726 p_doc_cost_center IN VARCHAR2,
7727 p_approval_amount IN NUMBER,
7728 p_item_key IN VARCHAR2,
7729 p_item_type IN VARCHAR2,
7730 p_final_approver_id OUT NOCOPY NUMBER,
7731 p_error_message OUT NOCOPY VARCHAR2,
7732 p_instructions OUT NOCOPY VARCHAR2,
7733 p_special_instr OUT NOCOPY VARCHAR2) IS
7734 ---------------------------------------------------------------------------
7735 l_approver_id NUMBER;
7736 l_approver_id_out NUMBER; -- Bug 2718416
7737 l_debug_info VARCHAR2(200);
7738 TYPE l_ManagerIDList IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
7739 l_manager_id l_ManagerIDList;
7740 l_counter NUMBER := 1;
7741 -- 3257576
7742 l_approver_status per_assignment_status_types.per_system_status%type;
7743 l_approver_name per_people_x.full_name%type;
7744 l_approver_name_out per_people_x.full_name%type;
7745 l_employee_name per_people_x.full_name%type;
7746
7747 l_last_approver_id NUMBER;
7748 l_last_approver_name per_workforce_x.full_name%TYPE;
7749 l_emp_info_rec AP_WEB_DB_HR_INT_PKG.EmployeeInfoRec;
7750
7751 BEGIN
7752
7753 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetFinalApprover');
7754
7755 IF (p_override_approver_id IS NULL) THEN
7756
7757 -- bug 3257576
7758 GetManagerInfoAndCheckStatus( p_employee_id,
7759 l_employee_name,
7760 l_approver_id,
7761 l_approver_name,
7762 l_approver_status,
7763 p_error_message,
7764 p_instructions,
7765 p_special_instr);
7766
7767 IF (p_error_message IS NOT NULL) THEN
7768 p_final_approver_id := NULL;
7769 END IF;
7770
7771 ELSE
7772
7773 l_approver_id := p_override_approver_id;
7774
7775 END IF;
7776
7777 -- 3257576
7778 IF ((l_approver_id IS NOT NULL) AND (p_error_message IS NULL)) THEN
7779
7780 /*Bug 2492342 Setting the value of the 1st Manager */
7781 l_manager_id(l_counter) := l_approver_id;
7782
7783 LOOP
7784
7785 l_counter := l_counter + 1;
7786
7787 IF (AP_WEB_EXPENSE_CUST_WF.HasAuthority(l_approver_id,
7788 p_doc_cost_center,
7789 p_approval_amount,
7790 p_item_key,
7791 p_item_type)) THEN
7792 p_final_approver_id := l_approver_id;
7793 return;
7794 END IF;
7795
7796 -- bug 3257576
7797 GetManagerInfoAndCheckStatus(
7798 l_approver_id,
7799 l_approver_name,
7800 l_approver_id_out,
7801 l_approver_name_out,
7802 l_approver_status,
7803 p_error_message,
7804 p_instructions,
7805 p_special_instr);
7806
7807 IF (p_error_message IS NOT NULL) THEN
7808 p_final_approver_id := NULL;
7809 return;
7810 END IF;
7811
7812 -- Bug 2718416 - do not pass in same variable as IN and OUT parameter
7813 l_approver_id := l_approver_id_out;
7814 l_approver_name := l_approver_name_out;
7815
7816 IF (l_approver_id = p_employee_id) THEN
7817 ---------------------------------------------
7818 l_debug_info := 'Loop in Approval Hierarchy';
7819 ---------------------------------------------
7820 -- 3257576
7821 FND_MESSAGE.Set_Name('SQLAP', 'AP_WEB_APRVL_HIERARCHY_LOOP');
7822 p_error_message := FND_MESSAGE.Get;
7823 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR6');
7824 p_instructions := FND_MESSAGE.Get;
7825 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_SPL_INSTR');
7826 p_special_instr := FND_MESSAGE.Get;
7827 return;
7828 END IF;
7829
7830 /*Bug 2492342 : Adding the manager to the table and checking whether
7831 this manager has been come across before. If so, there
7832 is a loop in the hierarchy.*/
7833
7834 l_manager_id(l_counter) := l_approver_id;
7835
7836 FOR i in 1..(l_counter -1) LOOP
7837
7838 IF l_approver_id = l_manager_id(i) THEN
7839 ---------------------------------------------
7840 l_debug_info := 'Loop in Approval Hierarchy';
7841 ---------------------------------------------
7842 -- 3257576
7843 FND_MESSAGE.Set_Name('SQLAP', 'AP_WEB_APRVL_HIERARCHY_LOOP');
7844 p_error_message := FND_MESSAGE.Get;
7845 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR6');
7846 p_instructions := FND_MESSAGE.Get;
7847 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_SPL_INSTR');
7848 p_special_instr := FND_MESSAGE.Get;
7849 return;
7850 END IF;
7851
7852 END LOOP;
7853
7854
7855 END LOOP;
7856
7857 END IF; -- l_approver_id is not null and p_error_message is null
7858
7859 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetFinalApprover');
7860
7861 EXCEPTION
7862 WHEN OTHERS THEN
7863 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetFinalApprover',
7864 p_item_type, null, null, l_debug_info);
7865 raise;
7866 END GetFinalApprover;
7867
7868 ----------------------------------------------------------------------
7869 PROCEDURE GetPreparerManager(p_item_type IN VARCHAR2,
7870 p_item_key IN VARCHAR2,
7871 p_actid IN NUMBER,
7872 p_funmode IN VARCHAR2,
7873 p_result OUT NOCOPY VARCHAR2) IS
7874 ----------------------------------------------------------------------
7875 l_preparer_id NUMBER;
7876 l_manager_id NUMBER;
7877 l_debug_info VARCHAR2(200);
7878 BEGIN
7879
7880 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetPreparerManager');
7881
7882 IF (p_funmode = 'RUN') THEN
7883
7884 ------------------------------------------------------
7885 l_debug_info := 'Retrieve Employee_ID Item Attribute';
7886 ------------------------------------------------------
7887 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7888 p_item_key,
7889 'PREPARER_ID');
7890
7891
7892 ---------------------------------------------
7893 l_debug_info := 'Call Get Manager Procedure';
7894 ----------------------------------------------
7895 GetManager(l_preparer_id,
7896 l_manager_id);
7897
7898 IF (l_manager_id IS NULL) THEN
7899 l_debug_info := 'Manager not found for employee_id ' || to_char(l_preparer_id);
7900 END IF;
7901
7902 SetPersonAs(l_manager_id,
7903 p_item_type,
7904 p_item_key,
7905 'MANAGER');
7906
7907 ELSIF (p_funmode = 'CANCEL') THEN
7908
7909 p_result := 'COMPLETE';
7910
7911 END IF;
7912
7913 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetPreparerManager');
7914
7915 EXCEPTION
7916 WHEN OTHERS THEN
7917 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetPreparerManager',
7918 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
7919 raise;
7920 END GetPreparerManager;
7921
7922 ----------------------------------------------------------------------
7923 PROCEDURE GetApproverManager(p_item_type IN VARCHAR2,
7924 p_item_key IN VARCHAR2,
7925 p_actid IN NUMBER,
7926 p_funmode IN VARCHAR2,
7927 p_result OUT NOCOPY VARCHAR2) IS
7928 ----------------------------------------------------------------------
7929 l_approver_id NUMBER;
7930 l_manager_id NUMBER;
7931 l_debug_info VARCHAR2(200);
7932 BEGIN
7933
7934 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetApproverManager');
7935
7936 IF (p_funmode = 'RUN') THEN
7937
7938 ------------------------------------------------------
7939 l_debug_info := 'Retrieve Approve_ID Item Attribute';
7940 ------------------------------------------------------
7941 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7942 p_item_key,
7943 'APPROVER_ID');
7944
7945 ---------------------------------------------
7946 l_debug_info := 'Call Get Manager Procedure';
7947 ----------------------------------------------
7948 GetManager(l_approver_id,
7949 l_manager_id);
7950
7951 SetPersonAs(l_manager_id,
7952 p_item_type,
7953 p_item_key,
7954 'APPROVER');
7955
7956 /*
7957 SetForwardInfoInAME is called to forward the approval to the approver's
7958 manager when the approver doesn't response and got time-out
7959 */
7960 AP_WEB_WRAPPER_PKG.SetForwardInfoInAME(p_item_key,
7961 p_item_type);
7962
7963 ELSIF (p_funmode = 'CANCEL') THEN
7964
7965 p_result := 'COMPLETE';
7966
7967 END IF;
7968
7969 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetApproverManager');
7970
7971 EXCEPTION
7972 WHEN OTHERS THEN
7973 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetApproverManager',
7974 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
7975 raise;
7976 END GetApproverManager;
7977
7978 ----------------------------------------------------------------------
7979 PROCEDURE ApproverProvided(p_item_type IN VARCHAR2,
7980 p_item_key IN VARCHAR2,
7981 p_actid IN NUMBER,
7982 p_funmode IN VARCHAR2,
7983 p_result OUT NOCOPY VARCHAR2) IS
7984 ----------------------------------------------------------------------
7985 l_approver_id NUMBER;
7986 l_debug_info VARCHAR2(200);
7987 BEGIN
7988
7989 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ApproverProvided');
7990
7991 IF (p_funmode = 'RUN') THEN
7992
7993 ------------------------------------------------------
7994 l_debug_info := 'Retrieve Approve_ID Item Attribute';
7995 ------------------------------------------------------
7996 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
7997 p_item_key,
7998 'APPROVER_ID');
7999
8000 ---------------------------------------------------------------------------
8001 l_debug_info := 'If l_approver_id is not null return Y otherwise return N';
8002 ---------------------------------------------------------------------------
8003 IF (l_approver_id IS NOT NULL) THEN
8004 p_result := 'COMPLETE:Y';
8005 ELSE
8006 p_result := 'COMPLETE:N';
8007 END IF;
8008
8009 ELSIF (p_funmode = 'CANCEL') THEN
8010
8011 p_result := 'COMPLETE';
8012
8013 END IF;
8014
8015 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ApproverProvided');
8016
8017 EXCEPTION
8018 WHEN OTHERS THEN
8019 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ApproverProvided',
8020 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8021 raise;
8022 END ApproverProvided;
8023
8024 ----------------------------------------------------------------------
8025 PROCEDURE SameCostCenters(p_item_type IN VARCHAR2,
8026 p_item_key IN VARCHAR2,
8027 p_actid IN NUMBER,
8028 p_funmode IN VARCHAR2,
8029 p_result OUT NOCOPY VARCHAR2) IS
8030 ----------------------------------------------------------------------
8031 l_emp_cost_center VARCHAR2(240);
8032 l_report_cost_center VARCHAR2(240);
8033 l_debug_info VARCHAR2(200);
8034 BEGIN
8035
8036 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SameCostCenters');
8037
8038 IF (p_funmode = 'RUN') THEN
8039
8040 ---------------------------------------------------------------
8041 l_debug_info := 'Retrieve Employee Cost Center Item Attribute';
8042 ---------------------------------------------------------------
8043 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
8044 p_item_key,
8045 'EMP_COST_CENTER');
8046
8047 ---------------------------------------------------------------
8048 l_debug_info := 'Retrieve Document Cost Center Item Attribute';
8049 ---------------------------------------------------------------
8050 l_report_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
8051 p_item_key,
8052 'DOC_COST_CENTER');
8053
8054 --------------------------------------------------------------------
8055 l_debug_info := 'If Employee and Document Cost Centers are the same
8056 return Y otherwise return N';
8057 --------------------------------------------------------------------
8058 IF (l_emp_cost_center = l_report_cost_center) THEN
8059 p_result := 'COMPLETE:Y';
8060 ELSE
8061 p_result := 'COMPLETE:N';
8062 END IF;
8063
8064 ELSIF (p_funmode = 'CANCEL') THEN
8065
8066 p_result := 'COMPLETE';
8067
8068 END IF;
8069
8070 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SameCostCenters');
8071
8072 EXCEPTION
8073 WHEN OTHERS THEN
8074 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SameCostCenters',
8075 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8076 raise;
8077 END SameCostCenters;
8078
8079 ----------------------------------------------------------------------
8080 PROCEDURE SetApproverEqualManager(p_item_type IN VARCHAR2,
8081 p_item_key IN VARCHAR2,
8082 p_actid IN NUMBER,
8083 p_funmode IN VARCHAR2,
8084 p_result OUT NOCOPY VARCHAR2) IS
8085 ----------------------------------------------------------------------
8086 l_manager_id NUMBER;
8087 l_manager_name wf_users.name%type;
8088 l_manager_display_name wf_users.display_name%type;
8089 l_debug_info VARCHAR2(200);
8090 BEGIN
8091
8092 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetApproverEqualManager');
8093
8094 IF (p_funmode = 'RUN') THEN
8095
8096 ------------------------------------------------------
8097 l_debug_info := 'Retrieve Manager_ID Item Attribute';
8098 -------------------------------------------------------
8099 l_manager_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8100 p_item_key,
8101 'MANAGER_ID');
8102
8103 ------------------------------------------------------------
8104 l_debug_info := 'Retrieve Manager_Name Info Item Attributes';
8105 ------------------------------------------------------------
8106 l_manager_name := WF_ENGINE.GetItemAttrText(p_item_type,
8107 p_item_key,
8108 'MANAGER_NAME');
8109
8110 l_manager_display_name := WF_ENGINE.GetItemAttrText(p_item_type,
8111 p_item_key,
8112 'MANAGER_DISPLAY_NAME');
8113
8114 ----------------------------------------------------------------------
8115 l_debug_info := 'Set Approver Info Item Attributes with Manager Info';
8116 ----------------------------------------------------------------------
8117 WF_ENGINE.SetItemAttrNUMBER(p_item_type,
8118 p_item_key,
8119 'APPROVER_ID',
8120 l_manager_id);
8121
8122 WF_ENGINE.SetItemAttrText(p_item_type,
8123 p_item_key,
8124 'APPROVER_NAME',
8125 l_manager_name);
8126
8127 WF_ENGINE.SetItemAttrText(p_item_type,
8128 p_item_key,
8129 'APPROVER_DISPLAY_NAME',
8130 l_manager_display_name);
8131
8132 ELSIF (p_funmode = 'CANCEL') THEN
8133
8134 p_result := 'COMPLETE';
8135
8136 END IF;
8137
8138 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetApproverEqualManager');
8139
8140 EXCEPTION
8141 WHEN OTHERS THEN
8142 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetApproverEqualManager',
8143 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8144 raise;
8145 END SetApproverEqualManager;
8146
8147 ----------------------------------------------------------------------
8148 PROCEDURE RecordForwardFromInfo(p_item_type IN VARCHAR2,
8149 p_item_key IN VARCHAR2,
8150 p_actid IN NUMBER,
8151 p_funmode IN VARCHAR2,
8152 p_result OUT NOCOPY VARCHAR2) IS
8153 ----------------------------------------------------------------------
8154 l_approver_id NUMBER;
8155 l_approver_name wf_users.name%type;
8156 l_approver_display_name wf_users.display_name%type;
8157 l_debug_info VARCHAR2(200);
8158 BEGIN
8159
8160 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start RecordForwardFromInfo');
8161
8162 IF (p_funmode in ('RUN', 'TRANSFER')) THEN
8163
8164 ------------------------------------------------------------
8165 l_debug_info := 'Retrieve Approver_Info Item Attributes';
8166 ------------------------------------------------------------
8167 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8168 p_item_key,
8169 'APPROVER_ID');
8170
8171 l_approver_name := WF_ENGINE.GetItemAttrText(p_item_type,
8172 p_item_key,
8173 'APPROVER_NAME');
8174
8175 l_approver_display_name := WF_ENGINE.GetItemAttrText(p_item_type,
8176 p_item_key,
8177 'APPROVER_DISPLAY_NAME');
8178
8179 ----------------------------------------------------------------------
8180 l_debug_info := 'Set Forward_From Item Attributes With Approver Info';
8181 ----------------------------------------------------------------------
8182 WF_ENGINE.SetItemAttrNUMBER(p_item_type,
8183 p_item_key,
8184 'FORWARD_FROM_ID',
8185 l_approver_id);
8186
8187 WF_ENGINE.SetItemAttrText(p_item_type,
8188 p_item_key,
8189 'FORWARD_FROM_NAME',
8190 l_approver_name);
8191
8192 WF_ENGINE.SetItemAttrText(p_item_type,
8193 p_item_key,
8194 'FORWARD_FROM_DISPLAY_NAME',
8195 l_approver_display_name);
8196
8197 ELSIF (p_funmode = 'CANCEL') THEN
8198
8199 p_result := 'COMPLETE';
8200
8201 END IF;
8202
8203 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end RecordForwardFromInfo');
8204
8205 EXCEPTION
8206 WHEN OTHERS THEN
8207 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'RecordForwardFromInfo',
8208 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8209 raise;
8210 END RecordForwardFromInfo;
8211
8212 ----------------------------------------------------------------------
8213 PROCEDURE ManagerNotEqualToApprover(p_item_type IN VARCHAR2,
8214 p_item_key IN VARCHAR2,
8215 p_actid IN NUMBER,
8216 p_funmode IN VARCHAR2,
8217 p_result OUT NOCOPY VARCHAR2) IS
8218 ----------------------------------------------------------------------
8219 l_approver_id NUMBER;
8220 l_manager_id NUMBER;
8221 l_debug_info VARCHAR2(200);
8222 BEGIN
8223
8224 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ManagerNotEqualToApprover');
8225
8226 IF (p_funmode = 'RUN') THEN
8227
8228 ------------------------------------------------------
8229 l_debug_info := 'Retrieve Approver_ID Item Attribute';
8230 ------------------------------------------------------
8231 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8232 p_item_key,
8233 'APPROVER_ID');
8234
8235 ------------------------------------------------------
8236 l_debug_info := 'Retrieve Approve_ID Item Attribute';
8237 ------------------------------------------------------
8238 l_manager_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8239 p_item_key,
8240 'MANAGER_ID');
8241
8242 IF (l_approver_id <> l_manager_id) THEN
8243 p_result := 'COMPLETE:Y';
8244 ELSE
8245 p_result := 'COMPLETE:N';
8246 END IF;
8247
8248 ELSIF (p_funmode = 'CANCEL') THEN
8249
8250 p_result := 'COMPLETE';
8251
8252 END IF;
8253
8254 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ManagerNotEqualToApprover');
8255
8256 EXCEPTION
8257 WHEN OTHERS THEN
8258 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ManagerNotEqualToApprover',
8259 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8260 raise;
8261 END ManagerNotEqualToApprover;
8262
8263 ----------------------------------------------------------------------
8264 PROCEDURE NotifyPreparer(p_item_type IN VARCHAR2,
8265 p_item_key IN VARCHAR2,
8266 p_actid IN NUMBER,
8267 p_funmode IN VARCHAR2,
8268 p_result OUT NOCOPY VARCHAR2) IS
8269 ----------------------------------------------------------------------
8270 l_approver_id NUMBER;
8271 l_manager_id NUMBER;
8272 l_count NUMBER;
8273 l_limit NUMBER;
8274 l_debug_info VARCHAR2(200);
8275 BEGIN
8276
8277 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start NotifyPreparer');
8278
8279 IF (p_funmode = 'RUN') THEN
8280
8281 -----------------------------------------------------------------------
8282 l_debug_info := 'Retrieve Manager_Approval_Send_Count Item Attribute';
8283 -----------------------------------------------------------------------
8284 l_count := WF_ENGINE.GetItemAttrNumber(p_item_type,
8285 p_item_key,
8286 'MANAGER_APPROVAL_SEND_COUNT');
8287
8288 ---------------------------------------------------------------
8289 l_debug_info := 'Retrieve Manager_Send_Limit Item Attribute';
8290 ---------------------------------------------------------------
8291 l_limit := WF_ENGINE.GetActivityAttrNumber(p_item_type,
8292 p_item_key,
8293 p_actid,
8294 'MANAGER_SEND_LIMIT');
8295
8296 -----------------------------------------------------------------------
8297 l_debug_info := 'Increment Manager_Approval_Send_Count Item Attribute';
8298 -----------------------------------------------------------------------
8299 WF_ENGINE.SetItemAttrNumber(p_item_type,
8300 p_item_key,
8301 'MANAGER_APPROVAL_SEND_COUNT',
8302 l_count+1);
8303
8304
8305 IF (l_count+1 >= l_limit) THEN
8306
8307 ---------------------------------------------------------------
8308 l_debug_info := 'Send_count at least equals limit, clear
8309 Manager_Approval_Send_Count Item Attribute
8310 and return Y';
8311 ---------------------------------------------------------------
8312 WF_ENGINE.SetItemAttrNumber(p_item_type,
8313 p_item_key,
8314 'MANAGER_APPROVAL_SEND_COUNT',
8315 0);
8316
8317 p_result := 'COMPLETE:Y';
8318
8319 ELSE
8320
8321 p_result := 'COMPLETE:N';
8322
8323 END IF;
8324
8325 ELSIF (p_funmode = 'CANCEL') THEN
8326
8327 p_result := 'COMPLETE';
8328
8329 END IF;
8330
8331 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end NotifyPreparer');
8332
8333 EXCEPTION
8334 WHEN OTHERS THEN
8335 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'NotifyPreparer',
8336 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8337 raise;
8338 END NotifyPreparer;
8339
8340 /*----------------------------------------------------------------------------*
8341 | Procedure
8342 | AMEEnabled
8343 |
8344 | DESCRIPTION
8345 | This procedure is used by workflow to determine whether AME is
8346 | enabled or not
8347 |
8348 | PARAMETERS
8349 |
8350 | RETURNS
8351 | none
8352 *----------------------------------------------------------------------------*/
8353 ---------------------------------------------------------
8354 PROCEDURE AMEEnabled(p_item_type IN VARCHAR2,
8355 p_item_key IN VARCHAR2,
8356 p_actid IN NUMBER,
8357 p_funmode IN VARCHAR2,
8358 p_result OUT NOCOPY VARCHAR2) IS
8359 ---------------------------------------------------------
8360 l_find_approver_count NUMBER;
8361 l_debug_info VARCHAR2(200);
8362 l_AMEEnabled VARCHAR2(1);
8363 l_bAMEProfileDefined BOOLEAN;
8364 l_nRespId Number;
8365
8366 BEGIN
8367
8368 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMEEnabled');
8369
8370 IF (p_funmode = 'RUN') THEN
8371
8372 BEGIN
8373 ------------------------------------------------------------
8374 l_debug_info := 'Get responsibility id';
8375 ------------------------------------------------------------
8376 l_nRespId := WF_ENGINE.GetItemAttrNumber(p_item_type,
8377 p_item_key,
8378 'RESPONSIBILITY_ID');
8379
8380 EXCEPTION
8381 WHEN OTHERS THEN
8382 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
8383 null;
8384 else
8385 raise;
8386 end if;
8387 END;
8388
8389 ----------------------------------------------------
8390 l_debug_info := 'Retrieve profile option AME Enabled';
8391 ----------------------------------------------------
8392 FND_PROFILE.GET_SPECIFIC('AME_INSTALLED_FLAG', null, l_nRespId, 200, l_AMEEnabled, l_bAMEProfileDefined);
8393
8394 if l_bAMEProfileDefined then
8395 -----------------------------------------------
8396 -- for bug 3344280, check the profile option value if it's defined
8397 -----------------------------------------------
8398 if (NVL(l_AMEEnabled,'N') = 'Y') then
8399 p_result := 'COMPLETE:Y';
8400 else
8401 p_result := 'COMPLETE:N';
8402 end if;
8403 else
8404 ---------------------------------------------------
8405 -- return no if AME Installed profile option is not defined
8406 ---------------------------------------------------
8407 p_result := 'COMPLETE:N';
8408 end if;
8409
8410 ELSIF (p_funmode = 'CANCEL') THEN
8411
8412 p_result := 'COMPLETE';
8413
8414 END IF;
8415
8416 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMEEnabled');
8417
8418 EXCEPTION
8419 WHEN OTHERS THEN
8420 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMEEnabled',
8421 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8422 raise;
8423 END AMEEnabled;
8424
8425 ---------------------------------------------------------
8426 PROCEDURE FirstApprover(p_item_type IN VARCHAR2,
8427 p_item_key IN VARCHAR2,
8428 p_actid IN NUMBER,
8429 p_funmode IN VARCHAR2,
8430 p_result OUT NOCOPY VARCHAR2) IS
8431 ---------------------------------------------------------
8432 l_find_approver_count NUMBER;
8433 l_debug_info VARCHAR2(200);
8434 BEGIN
8435
8436 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start FirstApprover');
8437
8438 IF (p_funmode = 'RUN') THEN
8439
8440 ----------------------------------------------------------------
8441 l_debug_info := 'Retrieving Find_Approver_Count Item Attribute';
8442 ----------------------------------------------------------------
8443 l_find_approver_count := WF_ENGINE.GetItemAttrNumber(p_item_type,
8444 p_item_key,
8445 'FIND_APPROVER_COUNT');
8446
8447 IF (l_find_approver_count = 1) THEN
8448 -----------------------------------------------
8449 -- return yes when find_approver_count equals 1
8450 -----------------------------------------------
8451 p_result := 'COMPLETE:Y';
8452 ELSE
8453 ---------------------------------------------------
8454 -- return no if find_approver_count doesn't equal 1
8455 ---------------------------------------------------
8456 p_result := 'COMPLETE:N';
8457 END IF;
8458
8459 ELSIF (p_funmode = 'CANCEL') THEN
8460
8461 p_result := 'COMPLETE';
8462
8463 END IF;
8464
8465 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end FirstApprover');
8466
8467 EXCEPTION
8468 WHEN OTHERS THEN
8469 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'FirstApprover',
8470 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8471 raise;
8472 END FirstApprover;
8473
8474 ---------------------------------------------------------
8475 PROCEDURE ApprovalForwarded(p_item_type IN VARCHAR2,
8476 p_item_key IN VARCHAR2,
8477 p_actid IN NUMBER,
8478 p_funmode IN VARCHAR2,
8479 p_result OUT NOCOPY VARCHAR2) IS
8480 ---------------------------------------------------------
8481 l_forward_from_id NUMBER;
8482 l_debug_info VARCHAR2(200);
8483 BEGIN
8484
8485 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ApprovalForwarded');
8486
8487 IF (p_funmode = 'RUN') THEN
8488
8489 ----------------------------------------------------------------
8490 l_debug_info := 'Retrieving FORWARD_FROM_ID Item Attribute';
8491 ----------------------------------------------------------------
8492 l_forward_from_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8493 p_item_key,
8494 'FORWARD_FROM_ID');
8495
8496 IF (l_forward_from_id IS NOT NULL) THEN
8497 -----------------------------------------------
8498 -- return yes when forward_from_id is not null
8499 -----------------------------------------------
8500 p_result := 'COMPLETE:Y';
8501 ELSE
8502 ----------------------------------------
8503 -- return no if forward_from_id is null
8504 ----------------------------------------
8505 p_result := 'COMPLETE:N';
8506 END IF;
8507
8508 ELSIF (p_funmode = 'CANCEL') THEN
8509 p_result := 'COMPLETE';
8510 END IF;
8511
8512 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ApprovalForwarded');
8513
8514 EXCEPTION
8515 WHEN OTHERS THEN
8516 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ApprovalForwarded',
8517 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8518 raise;
8519 END ApprovalForwarded;
8520
8521 ---------------------------------------------------------
8522 PROCEDURE ResetEmpCostCenter(p_item_type IN VARCHAR2,
8523 p_item_key IN VARCHAR2,
8524 p_actid IN NUMBER,
8525 p_funmode IN VARCHAR2,
8526 p_result OUT NOCOPY VARCHAR2) IS
8527 ---------------------------------------------------------
8528 l_preparer_id NUMBER;
8529 l_emp_name wf_users.name%type;
8530 l_emp_num VARCHAR2(30);
8531 l_emp_cost_center VARCHAR2(240);
8532 l_debug_info VARCHAR2(200);
8533 BEGIN
8534
8535 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetEmpCostCenter');
8536
8537 IF (p_funmode = 'RUN') THEN
8538
8539 -------------------------------------------------------------
8540 l_debug_info := 'Retrieving Emp_Cost_Center Item Attribute';
8541 -------------------------------------------------------------
8542 l_emp_cost_center := WF_ENGINE.GetItemAttrText(p_item_type,
8543 p_item_key,
8544 'EMP_COST_CENTER');
8545
8546 ---------------------------------------------------------
8547 l_debug_info := 'Retrieving Preparer_Id Item Attribute';
8548 ---------------------------------------------------------
8549 l_preparer_id := WF_ENGINE.GetItemAttrText(p_item_type,
8550 p_item_key,
8551 'PREPARER_ID');
8552
8553
8554 IF (l_emp_cost_center IS NULL) THEN
8555
8556 ---------------------------------------------------------------
8557 l_debug_info := 'Get the Employee Cost Center Associated With
8558 Preparer_Id';
8559 ---------------------------------------------------------------
8560 AP_WEB_UTILITIES_PKG.GetEmployeeInfo(l_emp_name,
8561 l_emp_num,
8562 l_emp_cost_center,
8563 l_preparer_id);
8564
8565 -------------------------------------------------------------
8566 l_debug_info := 'Set Emp_Cost_Center Item Attribute';
8567 -------------------------------------------------------------
8568 WF_ENGINE.SetItemAttrText(p_item_type,
8569 p_item_key,
8570 'EMP_COST_CENTER',
8571 l_emp_cost_center);
8572
8573 END IF;
8574
8575
8576 ELSIF (p_funmode = 'CANCEL') THEN
8577 p_result := 'COMPLETE';
8578 END IF;
8579
8580 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetEmpCostCenter');
8581
8582 EXCEPTION
8583 WHEN OTHERS THEN
8584 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ResetEmpCostCenter',
8585 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8586 raise;
8587 END ResetEmpCostCenter;
8588
8589 ---------------------------------------------------------
8590 PROCEDURE PayablesReviewed(p_item_type IN VARCHAR2,
8591 p_item_key IN VARCHAR2,
8592 p_actid IN NUMBER,
8593 p_funmode IN VARCHAR2,
8594 p_result OUT NOCOPY VARCHAR2) IS
8595 ---------------------------------------------------------
8596 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
8597 l_WorkflowRec AP_WEB_DB_EXPRPT_PKG.ExpWorkflowRec;
8598 l_debug_info VARCHAR2(200);
8599 l_rejection_reason Wf_Item_Attribute_Values.TEXT_VALUE%TYPE := NULL;
8600 BEGIN
8601
8602 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start PayablesReviewed');
8603
8604 IF (p_funmode = 'RUN') THEN
8605
8606 ----------------------------------------------------------------
8607 l_debug_info := 'Retrieving EXPENSE_REPORT_ID Item Attribute';
8608 ----------------------------------------------------------------
8609 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8610 p_item_key,
8611 'EXPENSE_REPORT_ID');
8612
8613 ----------------------------------------------------------------
8614 l_debug_info := 'Set Rejection Reason to No reason provided if it is null';
8615 ----------------------------------------------------------------
8616 l_rejection_reason := WF_ENGINE.GetItemAttrText(p_item_type,
8617 p_item_key,
8618 'WF_NOTE');
8619
8620 IF (l_rejection_reason IS NULL OR
8621 replace(l_rejection_reason, ' ', '') = '') THEN
8622 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_REASON_PROVIDED');
8623 WF_ENGINE.SetItemAttrText(p_item_type,
8624 p_item_key,
8625 'WF_NOTE',
8626 FND_MESSAGE.Get);
8627
8628 END IF;
8629
8630
8631
8632 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetExpWorkflowInfo(l_report_header_id,
8633 l_WorkflowRec)) THEN
8634 l_WorkflowRec.workflow_flag := NULL;
8635 END IF;
8636
8637 IF (l_WorkflowRec.workflow_flag = 'P') THEN
8638 ---------------------------------------------------------
8639 -- return yes when workflow_approved_flag is equal to 'P'
8640 ---------------------------------------------------------
8641 p_result := 'COMPLETE:Y';
8642 ELSE
8643 ----------------------------------------------------------
8644 -- return no if workflow_approved_flag is not equal to 'P'
8645 ----------------------------------------------------------
8646 p_result := 'COMPLETE:N';
8647 END IF;
8648
8649 ELSIF (p_funmode = 'CANCEL') THEN
8650 p_result := 'COMPLETE';
8651 END IF;
8652
8653 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end PayablesReviewed');
8654
8655 EXCEPTION
8656 WHEN OTHERS THEN
8657 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'PayablesReviewed',
8658 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8659 raise;
8660 END PayablesReviewed;
8661
8662 ----------------------------------------------------------------------
8663 PROCEDURE EmployeeEqualsToPreparer(p_item_type IN VARCHAR2,
8664 p_item_key IN VARCHAR2,
8665 p_actid IN NUMBER,
8666 p_funmode IN VARCHAR2,
8667 p_result OUT NOCOPY VARCHAR2) IS
8668 ----------------------------------------------------------------------
8669 l_employee_id NUMBER(15);
8670 l_preparer_id NUMBER(15);
8671 l_debug_info VARCHAR2(200);
8672 BEGIN
8673
8674 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start EmployeeEqualsToPreparer');
8675
8676 IF (p_funmode = 'RUN') THEN
8677
8678 ---------------------------------------------------------------
8679 l_debug_info := 'Retrieve Employee Id Item Attribute';
8680 ---------------------------------------------------------------
8681 l_employee_id := WF_ENGINE.GetItemAttrText(p_item_type,
8682 p_item_key,
8683 'EMPLOYEE_ID');
8684
8685 ---------------------------------------------------------------
8686 l_debug_info := 'Retrieve Preparer Id Item Attribute';
8687 ---------------------------------------------------------------
8688 l_preparer_id := WF_ENGINE.GetItemAttrText(p_item_type,
8689 p_item_key,
8690 'PREPARER_ID');
8691
8692 --------------------------------------------------------------------
8693 l_debug_info := 'If Employee Id and Preparer Id are the same
8694 return Y otherwise return N';
8695 --------------------------------------------------------------------
8696 IF (l_employee_id = l_preparer_id) THEN
8697 p_result := 'COMPLETE:Y';
8698 ELSE
8699 p_result := 'COMPLETE:N';
8700 END IF;
8701
8702 ELSIF (p_funmode = 'CANCEL') THEN
8703 p_result := 'COMPLETE';
8704 END IF;
8705
8706 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end EmployeeEqualsToPreparer');
8707
8708 EXCEPTION
8709 WHEN OTHERS THEN
8710 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'EmployeeEqualsToPreparer',
8711 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8712 raise;
8713 END EmployeeEqualsToPreparer;
8714
8715 ----------------------------------------------------------------------
8716 PROCEDURE EmployeeApprovalRequired(p_item_type IN VARCHAR2,
8717 p_item_key IN VARCHAR2,
8718 p_actid IN NUMBER,
8719 p_funmode IN VARCHAR2,
8720 p_result OUT NOCOPY VARCHAR2) IS
8721 ----------------------------------------------------------------------
8722 l_emp_method VARCHAR2(20);
8723 l_debug_info VARCHAR2(200);
8724 BEGIN
8725
8726 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start EmployeeApprovalRequired');
8727
8728 IF (p_funmode = 'RUN') THEN
8729
8730 -------------------------------------------------------------------
8731 l_debug_info := 'Retrieve Find_Approver_Method Activity Attribute';
8732 -------------------------------------------------------------------
8733 l_emp_method := WF_ENGINE.GetActivityAttrText(p_item_type,
8734 p_item_key,
8735 p_actid,
8736 'EMPLOYEE_APPROVAL_REQUIRED_MET');
8737
8738 IF (l_emp_method = 'Y') THEN
8739 p_result := 'COMPLETE:Y';
8740 ELSE
8741 p_result := 'COMPLETE:N';
8742 END IF;
8743
8744 ELSIF (p_funmode = 'CANCEL') THEN
8745 p_result := 'COMPLETE';
8746 END IF;
8747
8748 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end EmployeeApprovalRequired');
8749
8750 EXCEPTION
8751 WHEN OTHERS THEN
8752 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'EmployeeApprovalRequired',
8753 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8754 raise;
8755 END EmployeeApprovalRequired;
8756
8757 ---------------------------------------------------------
8758 PROCEDURE DetermineStartFromProcess(p_item_type IN VARCHAR2,
8759 p_item_key IN VARCHAR2,
8760 p_actid IN NUMBER,
8761 p_funmode IN VARCHAR2,
8762 p_result OUT NOCOPY VARCHAR2) IS
8763 ---------------------------------------------------------
8764
8765 --
8766 -- Determines from which process to start the workflow: server validation,
8767 -- manager approval, or ap approval.
8768 --
8769
8770 l_start_from_process VARCHAR2(40);
8771 l_workflow_approved_flag VARCHAR2(1);
8772 l_debug_info VARCHAR2(200);
8773 BEGIN
8774
8775 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start DetermineStartFromProcess');
8776
8777 IF (p_funmode = 'RUN') THEN
8778
8779 ----------------------------------------------------------------
8780 l_debug_info := 'Retrieving Start From Process Item Attribute';
8781 ----------------------------------------------------------------
8782 l_start_from_process := WF_ENGINE.GetItemAttrText(p_item_type,
8783 p_item_key,
8784 'START_FROM_PROCESS');
8785 p_result := 'COMPLETE:' || l_start_from_process;
8786 IF l_start_from_process IS NULL THEN
8787 p_result := 'COMPLETE:' || C_START_FROM_SERVER_VALIDATION;
8788 END IF;
8789
8790 ELSIF (p_funmode = 'CANCEL') THEN
8791 p_result := 'COMPLETE';
8792 END IF;
8793
8794 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end DetermineStartFromProcess');
8795
8796 EXCEPTION
8797 WHEN OTHERS THEN
8798 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'DetermineStartFromProcess',
8799 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8800 RAISE;
8801
8802 END DetermineStartFromProcess;
8803
8804 ---------------------------------------------------------
8805 PROCEDURE SetEmployeeAsApprover(p_item_type IN VARCHAR2,
8806 p_item_key IN VARCHAR2,
8807 p_actid IN NUMBER,
8808 p_funmode IN VARCHAR2,
8809 p_result OUT NOCOPY VARCHAR2) IS
8810 ---------------------------------------------------------
8811
8812 --
8813 -- For the third-party expense report submission, if the employee
8814 -- (not the submitter) rejects the report we must set the approver
8815 -- info to the employee so that the notification sent to the
8816 -- submitter will contain the appropriate rejector name. The approver
8817 -- info is used to determine the actual report approver not the
8818 -- employee in the third party case.
8819 --
8820
8821 V_employee_id NUMBER;
8822 V_employee_name wf_users.name%type;
8823 V_employee_display_name wf_users.display_name%type;
8824 l_debug_info VARCHAR2(200);
8825
8826 BEGIN
8827
8828 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetEmployeeAsApprover');
8829
8830 IF (p_funmode = 'RUN') THEN
8831
8832 ------------------------------------------------------
8833 l_debug_info := 'Get WF Employee_ID Item Attribute';
8834 ------------------------------------------------------
8835 V_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8836 p_item_key,
8837 'EMPLOYEE_ID');
8838
8839 V_employee_name := WF_ENGINE.GetItemAttrText(p_item_type,
8840 p_item_key,
8841 'EMPLOYEE_NAME');
8842
8843
8844 V_employee_display_name := WF_ENGINE.GetItemAttrText(p_item_type,
8845 p_item_key,
8846 'EMPLOYEE_DISPLAY_NAME');
8847
8848
8849 --------------------------------------------------------------
8850 l_debug_info := 'Set WF Preparer_Display_Name Item Attribute';
8851 --------------------------------------------------------------
8852 WF_ENGINE.SetItemAttrNumber(p_item_type,
8853 p_item_key,
8854 'APPROVER_ID',
8855 V_employee_id);
8856
8857 WF_ENGINE.SetItemAttrText(p_item_type,
8858 p_item_key,
8859 'APPROVER_NAME',
8860 V_employee_name);
8861
8862 WF_ENGINE.SetItemAttrText(p_item_type,
8863 p_item_key,
8864 'APPROVER_DISPLAY_NAME',
8865 V_employee_display_name);
8866
8867
8868 ELSIF (p_funmode = 'CANCEL') THEN
8869 p_result := 'COMPLETE';
8870 END IF;
8871
8872 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetEmployeeAsApprover');
8873
8874 EXCEPTION
8875 WHEN OTHERS THEN
8876 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetEmployeeAsApprover',
8877 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8878 RAISE;
8879
8880 END SetEmployeeAsApprover;
8881
8882 ----------------------------------------------------------------------
8883 PROCEDURE DeleteShortPayExpReport(p_item_type IN VARCHAR2,
8884 p_item_key IN VARCHAR2,
8885 p_actid IN NUMBER,
8886 p_funmode IN VARCHAR2,
8887 p_result OUT NOCOPY VARCHAR2) IS
8888 ----------------------------------------------------------------------
8889 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
8890 l_debug_info VARCHAR2(200);
8891 BEGIN
8892
8893 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start DeleteShortPayExpReport');
8894
8895 IF (p_funmode = 'RUN') THEN
8896
8897 ----------------------------------------------------------------
8898 l_debug_info := 'Retrieve New_Expense_Report_ID Item Attribute';
8899 ----------------------------------------------------------------
8900 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8901 p_item_key,
8902 'NEW_EXPENSE_REPORT_ID');
8903
8904 DeleteExpReportFromAPTables(l_report_header_id);
8905
8906 ELSIF (p_funmode = 'CANCEL') THEN
8907 p_result := 'COMPLETE';
8908 END IF;
8909
8910 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end DeleteShortPayExpReport');
8911
8912 EXCEPTION
8913 WHEN OTHERS THEN
8914 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'DeleteShortPayExpReport',
8915 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8916 raise;
8917 END DeleteShortPayExpReport;
8918
8919 ---------------------------------------------------------
8920 PROCEDURE RequireProofOfPayment(p_item_type IN VARCHAR2,
8921 p_item_key IN VARCHAR2,
8922 p_actid IN NUMBER,
8923 p_funmode IN VARCHAR2,
8924 p_result OUT NOCOPY VARCHAR2) IS
8925 ---------------------------------------------------------
8926 l_require_proof_of_payment VARCHAR2(1);
8927 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
8928 l_debug_info VARCHAR2(200);
8929 BEGIN
8930
8931 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start RequireProofOfPayment');
8932
8933 IF (p_funmode = 'RUN') THEN
8934
8935 ---------------------------------------------------------------------------
8936 l_debug_info := 'Retrieve Include_Missing_Receipts Activity Attribute';
8937 ---------------------------------------------------------------------------
8938 l_require_proof_of_payment := WF_ENGINE.GetActivityAttrText(p_item_type,
8939 p_item_key,
8940 p_actid,
8941 'ALWAYS_REQ_PROOF_OF_PAYMENT');
8942
8943 IF (l_require_proof_of_payment = 'N') THEN
8944
8945 ----------------------------------------------------------------
8946 l_debug_info := 'Retrieving EXPENSE_REPORT_ID Item Attribute';
8947 ----------------------------------------------------------------
8948 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
8949 p_item_key,
8950 'EXPENSE_REPORT_ID');
8951
8952
8953 IF (NOT AP_WEB_DB_EXPLINE_PKG.SetReceiptRequired(l_report_header_id, 'N')) THEN
8954 NULL;
8955 END IF;
8956
8957 END IF;
8958
8959 ELSIF (p_funmode = 'CANCEL') THEN
8960 p_result := 'COMPLETE';
8961 END IF;
8962
8963 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end RequireProofOfPayment');
8964
8965 EXCEPTION
8966 WHEN OTHERS THEN
8967 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'RequireProofOfPayment',
8968 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
8969 RAISE;
8970
8971 END RequireProofOfPayment;
8972
8973 /*
8974 Written by:
8975 Quan Le
8976 Purpose:
8977 To generate the value for LINE_TABLE document attribute of Expense Workflow. This procedure follows
8978 predefined API. See Workflow API documentation for more informfation.
8979 Input:
8980 See Workflow API documentation.
8981 Output:
8982 See Workflow API documentation.
8983 Input Output:
8984 See Workflow API documentation.
8985 Assumption:
8986 document_id is assumed to have the following format:
8987 <item_key>:<item_id>
8988 Date:
8989 1/4/99
8990 */
8991
8992 PROCEDURE GenerateExpLines(document_id IN VARCHAR2,
8993 display_type IN VARCHAR2,
8994 document IN OUT NOCOPY VARCHAR2,
8995 document_type IN OUT NOCOPY VARCHAR2) IS
8996
8997 l_document_max NUMBER := 25000; -- 27721 fails
8998 l_debug_info VARCHAR2(1000);
8999 l_message Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
9000 l_temp_clob CLOB;
9001 l_colon NUMBER;
9002 BEGIN
9003
9004 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateExpLines');
9005
9006 WF_NOTIFICATION.NewClob(l_temp_clob,document);
9007 GenerateExpClobLines(document_id,
9008 display_type,
9009 l_temp_clob,
9010 document_type);
9011 dbms_lob.read(l_temp_clob,l_document_max,1,document);
9012
9013 if (dbms_lob.getlength(l_temp_clob) > l_document_max) then
9014
9015 l_colon := instr(document, tr_end,-1);
9016 document := substr(document,1,l_colon+4);
9017 document := document || table_end || indent_end;
9018
9019 FND_MESSAGE.SET_NAME('SQLAP','AP_WEB_EXP_UNABLE_TO_SHOWLINES');
9020 l_message := FND_MESSAGE.GET;
9021 document := document || table_start;
9022 document := document || tr_start || '&' || 'nbsp;' || tr_end;
9023 document := document || tr_start || '&' || 'nbsp;' || tr_end;
9024 document := document || tr_start || td_start || l_message || td_end || tr_end;
9025 document := document || table_end || indent_end;
9026
9027 end if;
9028
9029 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateExpLines');
9030
9031 EXCEPTION
9032 WHEN OTHERS THEN
9033 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateExpLines',
9034 document_id, l_debug_info);
9035 raise;
9036 END GenerateExpLines;
9037
9038
9039 /*
9040 Written by:
9041 Quan Le
9042 Purpose:
9043 To generate the value for document attribute of Expense Workflow. This procedure follows
9044 predefined API. See Workflow API documentation for more informfation. Currently this procedure
9045 is used for PURPOSE attribute only.
9046 Input:
9047 See Workflow API documentation.
9048 Output:
9049 See Workflow API documentation.
9050 Input Output:
9051 See Workflow API documentation.
9052 Assumption:
9053 document_id is assumed to have the following format:
9054 <item_key>:<item_id>:<item attribute>
9055 Date:
9056 1/4/99
9057 */
9058 PROCEDURE GenerateDocumentAttributeValue(document_id IN VARCHAR2,
9059 display_type IN VARCHAR2,
9060 document IN OUT NOCOPY VARCHAR2,
9061 document_type IN OUT NOCOPY VARCHAR2) IS
9062 l_colon NUMBER;
9063 l_colon2 NUMBER;
9064 l_itemtype VARCHAR2(7);
9065 l_itemkey VARCHAR2(15);
9066 l_attribute VARCHAR2(30);
9067 l_debug_info VARCHAR2(1000);
9068 BEGIN
9069
9070 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateDocumentAttributeValue');
9071
9072 document := '';
9073
9074 l_debug_info := 'Decode document_id';
9075
9076 l_colon := instrb(document_id, ':');
9077 l_colon2 := instrb(document_id, ':', l_colon+1);
9078 l_itemtype := substrb(document_id, 1, l_colon - 1);
9079 l_itemkey := substrb(document_id, l_colon + 1, l_colon2 - l_colon -1);
9080 l_attribute := substrb(document_id, l_colon2 + 1);
9081
9082 if (display_type = 'text/plain') then
9083 if (l_attribute = 'PURPOSE') then
9084 document := WF_ENGINE.GetItemAttrText(l_itemtype,
9085 l_itemkey,
9086 'PURPOSE');
9087 end if;
9088 else -- html
9089 if (l_attribute = 'PURPOSE') then
9090 document := '<B>' || WF_ENGINE.GetItemAttrText(l_itemtype, l_itemkey, 'PURPOSE') || '</B>';
9091 end if;
9092 end if;
9093 document_type := display_type;
9094
9095 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateDocumentAttributeValue');
9096
9097 EXCEPTION
9098 WHEN OTHERS THEN
9099 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateDocumentAttributeValue',
9100 document_id, l_debug_info);
9101 raise;
9102 END GenerateDocumentAttributeValue;
9103
9104
9105
9106 /**
9107 * jrautiai ADJ Fix Removed shortpay and adjustment specific logic form elsewhere, so instead here
9108 * we are dealing with both cases using common logic.
9109 */
9110 PROCEDURE BuildAdjustmentInfoLine(p_display_type IN VARCHAR2,
9111 adjustment_rec IN AP_WEB_DB_EXPLINE_PKG.AdjustmentRecordType,
9112 p_adjustment_type IN VARCHAR2,
9113 p_currency IN VARCHAR2,
9114 p_adjustment_line IN OUT NOCOPY VARCHAR2) IS
9115
9116 l_debug_info VARCHAR2(1000);
9117 l_item_type VARCHAR2(30);
9118 l_report_header_id NUMBER;
9119 l_adjustment_line VARCHAR2(2000);
9120
9121 BEGIN
9122
9123 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start BuildAdjustmentInfoLine');
9124
9125 IF p_adjustment_type = 'ADJUSTMENT' THEN
9126 ------------------------------------------------------------------
9127 l_debug_info := 'Format Adjustment Line with amount' || adjustment_rec.amount;
9128 ------------------------------------------------------------------
9129 IF (p_display_type = 'text/plain') THEN
9130 l_adjustment_line := adjustment_rec.expense_type_disp || ' ' || adjustment_rec.amount || ' ' || adjustment_rec.adjustment_reason;
9131 p_adjustment_line := p_adjustment_line || '
9132 ' || l_adjustment_line;
9133 ELSE -- HTML type
9134 p_adjustment_line := p_adjustment_line || tr_start;
9135 -- 'Receipt Date'
9136 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.start_expense_date || td_end;
9137 -- 'Expense Type'
9138 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.expense_type_disp || td_end;
9139 -- 'Original Amount'
9140 p_adjustment_line := p_adjustment_line || td_number ||
9141 NVL(to_char(adjustment_rec.submitted_amount, FND_CURRENCY.Get_Format_Mask(p_currency,22)), '&' || 'nbsp;') || td_end;
9142 -- 'Adjustment'
9143 p_adjustment_line := p_adjustment_line || td_number ||
9144 NVL(to_char(adjustment_rec.adjusted_amount, FND_CURRENCY.Get_Format_Mask(p_currency,22)), '&' || 'nbsp;') || td_end;
9145 -- 'New Amount'
9146 p_adjustment_line := p_adjustment_line || td_number || to_char(adjustment_rec.amount, FND_CURRENCY.Get_Format_Mask(p_currency,22)) || td_end;
9147 -- 'Credit Card Expense'
9148 p_adjustment_line := p_adjustment_line || td_text || NVL(adjustment_rec.credit_card_expense_disp, '&' || 'nbsp;') || td_end;
9149 -- 'Justification'
9150 p_adjustment_line := p_adjustment_line || td_text || nvl(WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.justification), '&' || 'nbsp;') || td_end;
9151 -- 'Instructions'
9152 p_adjustment_line := p_adjustment_line || td_text;
9153 if (adjustment_rec.adjustment_reason_code_disp is not null) then
9154 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_code_disp) ||'<br>';
9155 else
9156 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9157 end if;
9158 if (adjustment_rec.adjustment_reason_description is not null) then
9159 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_description) ||'<br>';
9160 else
9161 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9162 end if;
9163 if (adjustment_rec.adjustment_reason is not null) then
9164 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason);
9165 else
9166 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9167 end if;
9168 p_adjustment_line := p_adjustment_line || td_end;
9169 p_adjustment_line := p_adjustment_line || tr_end;
9170 END IF;
9171 ELSIF p_adjustment_type = 'AUDIT' THEN
9172 IF (p_display_type = 'text/plain') THEN
9173 l_adjustment_line := adjustment_rec.expense_type_disp || ' ' || adjustment_rec.amount || ' ' || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason);
9174 p_adjustment_line := p_adjustment_line || '
9175 ' || l_adjustment_line;
9176 ELSE -- HTML type
9177 p_adjustment_line := p_adjustment_line || tr_start;
9178 -- 'Receipt Date'
9179 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.start_expense_date || td_end;
9180 -- 'Expense Type'
9181 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.expense_type_disp || td_end;
9182 -- 'Amount'
9183 p_adjustment_line := p_adjustment_line || td_number ||
9184 NVL(to_char(adjustment_rec.amount, FND_CURRENCY.Get_Format_Mask(p_currency,22)), '&' || 'nbsp;') || td_end;
9185 -- 'Justification'
9186 p_adjustment_line := p_adjustment_line || td_text || nvl(WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.justification), '&' || 'nbsp;') || td_end;
9187 -- 'Instructions'
9188 p_adjustment_line := p_adjustment_line || td_text;
9189 if (adjustment_rec.adjustment_reason_code_disp is not null) then
9190 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_code_disp) ||'<br>';
9191 else
9192 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9193 end if;
9194 if (adjustment_rec.adjustment_reason_description is not null) then
9195 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_description) ||'<br>';
9196 else
9197 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9198 end if;
9199 if (adjustment_rec.adjustment_reason is not null) then
9200 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason);
9201 else
9202 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9203 end if;
9204 p_adjustment_line := p_adjustment_line || td_end;
9205 p_adjustment_line := p_adjustment_line || tr_end;
9206 END IF;
9207 ELSE
9208 IF (p_display_type = 'text/plain') THEN
9209 l_adjustment_line := adjustment_rec.expense_type_disp || ' ' || adjustment_rec.amount || ' ' || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason);
9210 p_adjustment_line := p_adjustment_line || '
9211 ' || l_adjustment_line;
9212 ELSE -- HTML type
9213 p_adjustment_line := p_adjustment_line || tr_start;
9214 -- 'Receipt Date'
9215 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.start_expense_date || td_end;
9216 -- 'Expense Type'
9217 p_adjustment_line := p_adjustment_line || td_text || adjustment_rec.expense_type_disp || td_end;
9218 -- 'Amount'
9219 p_adjustment_line := p_adjustment_line || td_number ||
9220 NVL(to_char(adjustment_rec.amount, FND_CURRENCY.Get_Format_Mask(p_currency,22)), '&' || 'nbsp;') || td_end;
9221 -- 'Itemized Expense'
9222 p_adjustment_line := p_adjustment_line || td_text || NVL(adjustment_rec.itemized_expense_disp, '&' || 'nbsp;') || td_end;
9223 -- 'Justification'
9224 p_adjustment_line := p_adjustment_line || td_text || nvl(WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.justification), '&' || 'nbsp;') || td_end;
9225 -- 'Instructions'
9226 p_adjustment_line := p_adjustment_line || td_text;
9227 if (adjustment_rec.adjustment_reason_code_disp is not null) then
9228 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_code_disp) ||'<br>';
9229 else
9230 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9231 end if;
9232 if (adjustment_rec.adjustment_reason_description is not null) then
9233 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason_description) ||'<br>';
9234 else
9235 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9236 end if;
9237 if (adjustment_rec.adjustment_reason is not null) then
9238 p_adjustment_line := p_adjustment_line || WF_NOTIFICATION.SubstituteSpecialChars(adjustment_rec.adjustment_reason);
9239 else
9240 p_adjustment_line := p_adjustment_line || '&'||'nbsp;';
9241 end if;
9242 p_adjustment_line := p_adjustment_line || td_end;
9243 p_adjustment_line := p_adjustment_line || tr_end;
9244 END IF;
9245 END IF; -- p_adjustment_type = 'ADJUSTMENT'
9246
9247 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end BuildAdjustmentInfoLine');
9248
9249 EXCEPTION
9250 WHEN OTHERS THEN
9251 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'BuildAdjustmentInfoLine',
9252 '', l_debug_info);
9253 raise;
9254 END BuildAdjustmentInfoLine;
9255
9256
9257 PROCEDURE GenerateAdjustmentInfo(document_id IN VARCHAR2,
9258 display_type IN VARCHAR2,
9259 document IN OUT NOCOPY VARCHAR2,
9260 document_type IN OUT NOCOPY VARCHAR2) IS
9261 l_document_max NUMBER:=25000;
9262 l_debug_info VARCHAR2(1000);
9263 l_message VARCHAR2(2000);
9264 l_temp_clob CLOB;
9265 l_colon NUMBER;--namrata
9266 BEGIN
9267 WF_NOTIFICATION.NewClob(l_temp_clob,document);
9268
9269 GenerateAdjustmentInfoClob(document_id,
9270 display_type,
9271 l_temp_clob,
9272 document_type);
9273
9274 dbms_lob.read(l_temp_clob,l_document_max,1,document);
9275
9276 if (dbms_lob.getlength(l_temp_clob) > l_document_max) then
9277
9278 l_colon := instr(document, '</tr>',-1);
9279 document := substr(document,1,l_colon+4);
9280 document := document || '</table><br>';
9281
9282 FND_MESSAGE.SET_NAME('SQLAP','AP_WEB_EXP_UNABLE_TO_SHOWLINES');
9283 l_message := FND_MESSAGE.GET;
9284 document := document || '<table>';
9285 document := document || '<tr> </tr>';
9286 document := document || '<tr> </tr>';
9287 document := document || '<tr><td>' || l_message || '</td></tr>';
9288 document := document || '</table>';
9289
9290
9291 end if;
9292 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateAdjustmentInfo');
9293
9294 EXCEPTION
9295 WHEN OTHERS THEN
9296 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateAdjustmentInfo',
9297 document_id, l_debug_info);
9298 raise;
9299 END GenerateAdjustmentInfo;
9300
9301 --namrata
9302
9303 PROCEDURE GenerateAdjustmentInfoClob(document_id IN VARCHAR2,
9304 display_type IN VARCHAR2,
9305 document IN OUT NOCOPY CLOB,
9306 document_type IN OUT NOCOPY VARCHAR2) IS
9307
9308 l_document long;--namrata
9309 l_document_max NUMBER:=25000;--namrata
9310 l_debug_info VARCHAR2(1000);
9311 l_item_type VARCHAR2(30);
9312 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
9313 l_adjustment_line VARCHAR2(2000);
9314 l_adj_info_body VARCHAR2(2000);
9315 l_itemtype VARCHAR2(7);
9316 l_itemkey VARCHAR2(30);
9317 l_currency VARCHAR2(50);
9318 l_colon NUMBER;
9319
9320 -- Bug 3336259: CC SP and ADJ Fix
9321 l_adj_code VARCHAR2(100) := 'ADJUSTMENT'; --default is Adjustments
9322 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
9323 l_title AK_REGIONS_VL.name%TYPE;
9324
9325 -- Bug 3336259: CC SP and ADJ Fix, changed to refer the new cursor type.
9326 AdjustmentsCursor AP_WEB_DB_EXPLINE_PKG.AdjustmentCursorType;
9327
9328 -- Bug 3336259: CC SP and ADJ Fix, fetching the results into a record of a common type.
9329 adjustment_rec AP_WEB_DB_EXPLINE_PKG.AdjustmentRecordType;
9330
9331 l_colspan NUMBER :=0;
9332 l_total_adjustment NUMBER :=0;
9333 l_total_amount NUMBER :=0;
9334 l_total_disp NUMBER :=0;
9335
9336 l_n_org_id Number;
9337 BEGIN
9338
9339 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateAdjustmentInfo');
9340
9341 ------------------------------------------------------------
9342 l_debug_info := 'Decode document_id';
9343 ------------------------------------------------------------
9344 l_colon := instrb(document_id, ':');
9345
9346 ------------------------------------------------------------------------------
9347 l_debug_info := ' First index: ' || to_char(l_colon);
9348 ------------------------------------------------------------------------------
9349 l_itemtype := substrb(document_id, 1, l_colon - 1);
9350 l_itemkey := substrb(document_id, l_colon + 1);
9351
9352 ------------------------------------------------------------
9353 l_debug_info := 'Retrieve Adjustment Code';
9354 ------------------------------------------------------------
9355 l_colon := instrb(l_itemkey, ':');
9356 ------------------------------------------------------------------------------
9357 l_debug_info := 'Second index: ' || to_char(l_colon);
9358 ------------------------------------------------------------------------------
9359 l_adj_code := substrb(l_itemkey, l_colon + 1);
9360 l_itemkey := substrb(l_itemkey, 1, l_colon - 1);
9361
9362 ------------------------------------------------------------
9363 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
9364 ------------------------------------------------------------
9365 l_report_header_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
9366 l_itemkey,
9367 'EXPENSE_REPORT_ID');
9368
9369 ----------------------------------------------------
9370 l_debug_info := 'Retrieve Currency Item Attribute';
9371 ----------------------------------------------------
9372 l_currency := WF_ENGINE.GetItemAttrText(l_itemtype,
9373 l_itemkey,
9374 'CURRENCY');
9375
9376 --------------------------------------------
9377 l_debug_info := 'Get Org Id';
9378 --------------------------------------------
9379 begin
9380
9381 l_n_org_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
9382 l_itemkey,
9383 'ORG_ID');
9384 exception
9385 when others then
9386 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
9387 -- ORG_ID item attribute doesn't exist, need to add it
9388 WF_ENGINE.AddItemAttr(l_itemtype, l_itemkey, 'ORG_ID');
9389 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
9390 to_number(l_itemkey),
9391 l_n_org_id) <> TRUE ) THEN
9392 l_n_org_id := NULL;
9393 END IF;
9394
9395 WF_ENGINE.SetItemAttrNumber(l_itemtype,
9396 l_itemkey,
9397 'ORG_ID',
9398 l_n_org_ID);
9399 else
9400 raise;
9401 end if;
9402
9403 end;
9404
9405 -- MOAC UPTAKE --
9406 -- Should not have to initialize the org context
9407 -- This is done via callbackfunction()
9408 /*--------------------
9409 if (l_n_org_id is not null) then
9410 fnd_client_info.set_org_context(l_n_org_id);
9411 else
9412 -- Report was submitted before org_id being added, hence org_id
9413 -- item attributes hasn't been set yet. Need to get it from
9414 -- report header
9415 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
9416 to_number(l_itemkey),
9417 l_n_org_id) <> TRUE ) THEN
9418 l_n_org_id := NULL;
9419 END IF;
9420
9421 IF (l_n_org_id is not null) then
9422 fnd_client_info.set_org_context(l_n_org_id);
9423 END IF;
9424
9425 end if;
9426 ------------------------*/
9427
9428
9429 IF (display_type = 'text/plain') THEN
9430 l_document := '';
9431 ELSE -- HTML
9432 ----------------------------------
9433 l_debug_info := 'Get prompts';
9434 ----------------------------------
9435 AP_WEB_DISC_PKG.getPrompts(200,'AP_WEB_WF_LINETABLE',l_title,l_prompts);
9436
9437 /**
9438 * Bug 3336259: CC SP and ADJ Fix start
9439 * set the table header depending whether we are building adjustment, policy violation or missing receipts table
9440 */
9441 IF (l_adj_code = 'ADJUSTMENT') THEN
9442 l_document := '<b>' || l_prompts(16) || '</b><br>';
9443 ELSE
9444 IF (l_adj_code = 'POLICY') THEN
9445 l_document := '<b>' || l_prompts(17) || '</b><br>';
9446 ELSIF (l_adj_code = 'AUDIT') THEN -- no table header for AUDIT
9447 document := '<br>';
9448 ELSE -- missing receipts
9449 l_document := '<b>' || l_prompts(18) || '</b><br>';
9450 END IF;
9451 END IF;
9452 /**
9453 * Bug 3336259: CC SP and ADJ Fix end
9454 */
9455
9456 l_document := l_document || '<table bgcolor='||table_bgcolor||' width='||table_width||' border='||table_border||' cellpadding='||table_cellpadding||' cellspacing='||table_cellspacing||'>';
9457
9458 l_document := l_document || '<tr bgcolor='||th_bgcolor||'>';
9459 /**
9460 * Bug 3336259: CC SP and ADJ Fix start
9461 * set the table column headers depending whether we are building adjustment or shortpay table
9462 */
9463 IF (l_adj_code = 'ADJUSTMENT') THEN
9464 -- 'Receipt Date'
9465 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(4) || '</b></td>';
9466 -- 'Expense Type'
9467 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(5) || '</b></td>';
9468 -- 'Original Amount (REIMBURSEMENT_CURRENCY)'
9469 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(19) || ' ('||l_currency||')' || '</b></td>';
9470 -- 'Adjustment (REIMBURSEMENT_CURRENCY)'
9471 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(20) || ' ('||l_currency||')' || '</b></td>';
9472 -- 'New Amount (REIMBURSEMENT_CURRENCY)'
9473 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(21) || ' ('||l_currency||')' || '</b></td>';
9474 -- 'Credit Card Expense'
9475 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(22) || '</b></td>';
9476 -- 'Adjustment Reason'
9477 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(23) || '</b></td>';
9478 -- 'Adjustment Comments'
9479 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(11) || '</b></td></tr>';
9480 ELSE
9481 -- 'Receipt Date'
9482 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(4) || '</b></td>';
9483 -- 'Expense Type'
9484 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(5) || '</b></td>';
9485 -- 'Amount (REIMBURSEMENT_CURRENCY)'
9486 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(9) || ' ('||l_currency||')' || '</b></td>';
9487 -- 'Itemized Expense'
9488 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(24) || '</b></td>';
9489 -- 'Adjustment Reason'
9490 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(25) || '</b></td>';
9491 -- 'Adjustment Comments'
9492 l_document := l_document || '<td align="left"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(26) || '</b></td></tr>';
9493 END IF;
9494 /**
9495 * Bug 3336259: CC SP and ADJ Fix end
9496 */
9497 END IF;
9498
9499 ------------------------------------------
9500 l_debug_info := 'Read Adjustments Cursor';
9501 ------------------------------------------
9502
9503 /**
9504 Bug 3336259: CC SP and ADJ Fix Start - Removed shortpay and adjustment specific logic, instead we are using the same
9505 * logic for both in GetAdjustmentsCursor and BuildAdjustmentInfoLine.
9506 */
9507 IF (AP_WEB_DB_EXPLINE_PKG.GetAdjustmentsCursor(l_report_header_id, l_adj_code, AdjustmentsCursor)) THEN
9508 LOOP
9509 FETCH AdjustmentsCursor INTO adjustment_rec;
9510 EXIT WHEN AdjustmentsCursor%NOTFOUND;
9511 BuildAdjustmentInfoLine(display_type,
9512 adjustment_rec,
9513 l_adj_code,
9514 l_currency,
9515 l_document);--namrata
9516
9517 IF lengthb(l_document)>=l_document_max THEN
9518 WF_NOTIFICATION.WriteToClob(document,l_document);
9519 l_document:='';--namrata
9520 END IF;
9521
9522
9523 l_total_adjustment := l_total_adjustment + adjustment_rec.adjusted_amount;
9524 l_total_amount := l_total_amount + adjustment_rec.amount;
9525 END LOOP;
9526
9527 CLOSE AdjustmentsCursor;
9528 END IF;
9529
9530 /**
9531 * Bug 3336259: CC SP and ADJ Fix end
9532 */
9533
9534 IF (display_type = 'text/html') THEN
9535 /**
9536 * Bug 3336259: CC SP and ADJ Fix Start
9537 */
9538 --------------------------------------------
9539 l_debug_info := 'Generate Total Row';
9540 --------------------------------------------
9541 l_document := l_document || '<tr bgcolor='||th_bgcolor||'>';
9542
9543 IF l_adj_code = 'ADJUSTMENT' THEN
9544 -- display Total
9545 l_document := l_document || '<td colspan=3 align="right"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(12) || '</b></td>';
9546 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>';
9547 l_document := l_document || '<td colspan=4 align="right"><font color='||th_fontcolor||' face='||th_fontface||'></td>';
9548 ELSE
9549 l_document := l_document || '<td colspan=2 align="right"><font color='||th_fontcolor||' face='||th_fontface||'><b>' || l_prompts(12) || '</b></td>';
9550 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>';
9551 l_document := l_document || '<td colspan=3 align="right"><font color='||th_fontcolor||' face='||th_fontface||'></td>';
9552 END IF;
9553
9554 l_document := l_document || '</tr>';
9555 l_document := l_document || '</table><br>';
9556 /**
9557 * Bug 3336259: CC SP and ADJ Fix end
9558 */
9559 END IF;
9560
9561 IF l_document is not null THEN
9562 WF_NOTIFICATION.WriteToClob(document,l_document);
9563 END IF;
9564
9565 document_type := display_type;
9566
9567 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateAdjustmentInfoClob');
9568
9569 EXCEPTION
9570 WHEN OTHERS THEN
9571 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateAdjustmentInfoClob',
9572 document_id, l_debug_info);
9573 raise;
9574 END GenerateAdjustmentInfoClob;
9575
9576 PROCEDURE ResetLineInfo(document_id IN VARCHAR2,
9577 display_type IN VARCHAR2,
9578 document IN OUT NOCOPY VARCHAR2,
9579 document_type IN OUT NOCOPY VARCHAR2) IS
9580 l_debug_info VARCHAR2(1000);
9581 BEGIN
9582
9583 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetLineInfo');
9584
9585 ------------------------------------------------------------------
9586 l_debug_info := 'Reset Line Info Body';
9587 ------------------------------------------------------------------
9588
9589 document := '';
9590 document_type := display_type;
9591
9592 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetLineInfo');
9593
9594 EXCEPTION
9595 WHEN OTHERS THEN
9596 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ResetLineInfo',
9597 document_id, l_debug_info);
9598 raise;
9599 END ResetLineInfo;
9600
9601 ----------------------------------------------------------------------
9602 PROCEDURE CallbackFunction( p_s_item_type IN VARCHAR2,
9603 p_s_item_key IN VARCHAR2,
9604 p_n_actid IN NUMBER,
9605 p_s_command IN VARCHAR2,
9606 p_s_result OUT NOCOPY VARCHAR2) IS
9607 ----------------------------------------------------------------------
9608 l_n_org_id Number;
9609 l_n_user_id Number;
9610 l_n_resp_id Number;
9611 l_n_resp_appl_id Number;
9612 l_current_org_id Number;
9613 l_current_user_id Number;
9614 l_current_resp_id Number;
9615 l_current_resp_appl_id Number;
9616
9617
9618 BEGIN
9619
9620 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CallbackFunction');
9621
9622 begin
9623
9624 l_n_org_id := WF_ENGINE.GetItemAttrNumber(p_s_item_type,
9625 p_s_item_key,
9626 'ORG_ID');
9627 exception
9628 when others then
9629 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
9630 -- ORG_ID item attribute doesn't exist, need to add it
9631 wf_engine.AddItemAttr(p_s_item_type, p_s_item_key, 'ORG_ID');
9632 -- get the org_id from header for old reports
9633 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
9634 to_number(p_s_item_key),
9635 l_n_org_id) <> TRUE ) THEN
9636 l_n_org_id := NULL;
9637 END IF;
9638 WF_ENGINE.SetItemAttrNumber(p_s_item_type,
9639 p_s_item_key,
9640 'ORG_ID',
9641 l_n_org_id);
9642 else
9643 raise;
9644 end if;
9645
9646 end;
9647
9648 begin
9649 l_n_user_id := WF_ENGINE.GetItemAttrNumber(p_s_item_type,
9650 p_s_item_key,
9651 'USER_ID');
9652
9653 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(p_s_item_type,
9654 p_s_item_key,
9655 'RESPONSIBILITY_ID');
9656
9657 l_n_resp_appl_id := WF_ENGINE.GetItemAttrNumber(p_s_item_type,
9658 p_s_item_key,
9659 'APPLICATION_ID');
9660 exception
9661 when others then
9662 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
9663 null;
9664 else
9665 raise;
9666 end if;
9667 end;
9668
9669
9670 IF (p_s_command = 'SET_CTX') THEN
9671
9672 -- Set the context
9673 FND_GLOBAL.APPS_INITIALIZE( USER_ID => l_n_user_id,
9674 RESP_ID => l_n_resp_id,
9675 RESP_APPL_ID => l_n_resp_appl_id
9676 );
9677
9678 -- Set Org context
9679 -- Needs to be after FND_GLOBAL.APPS_INITIALIZE because
9680 -- user_id, resp_id, and appl_id may be null because
9681 -- the attributes don't exist or because they are not set
9682 if (l_n_org_id is not null) then
9683 mo_global.set_policy_context(p_access_mode => 'S',
9684 p_org_id => l_n_org_id);
9685 end if;
9686
9687 -- Set Accounting Flexfield validation context
9688 AP_WEB_DB_GL_INT_PKG.set_aff_validation_org_context(l_n_org_id);
9689
9690 ELSIF (p_s_command = 'TEST_CTX') THEN
9691
9692 /* Bug 4319321 : Need to check the values of user_id, resp_id
9693 * and resp_appl_id as well.
9694 */
9695 l_current_user_id := TO_NUMBER(FND_PROFILE.VALUE('USER_ID'));
9696 l_current_resp_id := TO_NUMBER(FND_PROFILE.VALUE('RESP_ID'));
9697 l_current_resp_appl_id := TO_NUMBER(FND_PROFILE.VALUE('RESP_APPL_ID'));
9698 l_current_org_id := nvl(mo_global.get_current_org_id, -99);
9699
9700 /* Bug 4711393 : Should return NOTSET instead of FALSE in test_ctx mode
9701 * so that the actual context can get set via call in
9702 * set_ctx mode. This would avoid incorrect deferred state
9703 */
9704 IF (nvl(mo_global.get_access_mode, 'NULL') <> 'S') THEN
9705 p_s_result := 'NOTSET';
9706 ELSIF l_n_user_id IS NULL
9707 OR l_n_resp_id IS NULL
9708 OR l_n_resp_appl_id IS NULL THEN
9709 /* This condition should not occur. But if it does, do not reset the context*/
9710 p_s_result := 'TRUE';
9711 ELSIF l_current_user_id IS NULL
9712 OR l_current_resp_id IS NULL
9713 OR l_current_resp_appl_id IS NULL
9714 OR l_current_resp_id = -1
9715 OR l_current_resp_appl_id = -1 THEN
9716 /* Context is not set as yet. It will be set in SET_CTX mode call */
9717 p_s_result := 'NOTSET';
9718 ELSIF l_n_user_id=l_current_user_id
9719 AND l_n_resp_id=l_current_resp_id
9720 AND l_n_resp_appl_id=l_current_resp_appl_id THEN
9721 IF l_n_org_id <> l_current_org_id THEN
9722 /* Context is incorrect. Need to set it correctly in SET_CTX mode */
9723 p_s_result := 'NOTSET';
9724 ELSE
9725 /* will come here if either of l_org_id or l_current_org_id is null or both are equal
9726 * l_org_id or l_current_org_id is NULL means single org environment
9727 */
9728 p_s_result := 'TRUE';
9729 END IF;
9730 ELSE
9731 p_s_result := 'NOTSET';
9732 END IF;
9733
9734 END IF;
9735
9736 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CallbackFunction');
9737
9738 END CallbackFunction;
9739
9740 ----------------------------------------------------------------------
9741 PROCEDURE IsPreparerToAuditorTransferred(
9742 p_item_type IN VARCHAR2,
9743 p_item_key IN VARCHAR2,
9744 p_actid IN NUMBER,
9745 p_funmode IN VARCHAR2,
9746 p_result OUT NOCOPY VARCHAR2) IS
9747 ----------------------------------------------------------------------
9748
9749 l_debug_info VARCHAR2(1000);
9750
9751 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
9752 l_entered_by NUMBER := fnd_global.user_id;
9753 l_role_info_tbl wf_directory.wf_local_roles_tbl_type;
9754
9755 l_orig_language_code ap_expense_params.note_language_code%type := null;
9756 l_orig_language fnd_languages.nls_language%type := null;
9757 l_new_language_code ap_expense_params.note_language_code%type := null;
9758 l_new_language fnd_languages.nls_language%type := null;
9759
9760 BEGIN
9761
9762 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start IsPreparerToAuditorTransferred');
9763
9764 if (p_funmode in ('QUESTION', 'ANSWER')) then
9765
9766 -------------------------------------------------------------------
9767 l_debug_info := 'Need to generate Note based on language setup';
9768 -------------------------------------------------------------------
9769
9770 -------------------------------------------------------------------
9771 l_debug_info := 'Save original language';
9772 -------------------------------------------------------------------
9773 l_orig_language_code := userenv('LANG');
9774 select nls_language
9775 into l_orig_language
9776 from fnd_languages
9777 where language_code = l_orig_language_code;
9778
9779 -------------------------------------------------------------------
9780 l_debug_info := 'Check AP_EXPENSE_PARAMS.NOTE_LANGUAGE_CODE';
9781 -------------------------------------------------------------------
9782 begin
9783 select note_language_code
9784 into l_new_language_code
9785 from ap_expense_params;
9786
9787 exception
9788 when no_data_found then
9789 null;
9790 end;
9791
9792 -------------------------------------------------------------------
9793 l_debug_info := 'Else use instance base language';
9794 -------------------------------------------------------------------
9795 if (l_new_language_code is null) then
9796 select language_code
9797 into l_new_language_code
9798 from fnd_languages
9799 where installed_flag in ('B');
9800 end if;
9801
9802 -------------------------------------------------------------------
9803 l_debug_info := 'Set nls context to new language';
9804 -------------------------------------------------------------------
9805 select nls_language
9806 into l_new_language
9807 from fnd_languages
9808 where language_code = l_new_language_code;
9809
9810 fnd_global.set_nls_context(p_nls_language => l_new_language);
9811
9812 ------------------------------------------------------------
9813 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
9814 ------------------------------------------------------------
9815 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
9816 p_item_key,
9817 'EXPENSE_REPORT_ID');
9818
9819 -----------------------------------------
9820 l_debug_info := 'Get the User Id';
9821 -----------------------------------------
9822 begin
9823
9824 WF_DIRECTORY.GetRoleInfo2(wf_engine.context_user, l_role_info_tbl);
9825 AP_WEB_OA_MAINFLOW_PKG.GetUserId(l_role_info_tbl(1).orig_system_id, l_entered_by);
9826
9827 exception
9828 when no_data_found then
9829 null;
9830 end;
9831
9832 ------------------------------------------------------------
9833 l_debug_info := 'store the Request More Info question/answer as a note';
9834 ------------------------------------------------------------
9835 AP_WEB_NOTES_PKG.CreateERPrepToAudNote (
9836 p_report_header_id => l_report_header_id,
9837 p_note => wf_core.translate(p_funmode)||'
9838 '||wf_engine.context_user_comment,
9839 p_lang => l_new_language_code,
9840 p_entered_by => l_entered_by
9841 );
9842
9843 -------------------------------------------------------------------
9844 l_debug_info := 'Restore nls context to original language';
9845 -------------------------------------------------------------------
9846 fnd_global.set_nls_context(p_nls_language => l_orig_language);
9847 END IF;
9848
9849 EXCEPTION
9850 WHEN OTHERS THEN
9851 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsPreparerToAuditorTransferred',
9852 p_item_type, p_item_key, to_char(0), l_debug_info);
9853 RAISE;
9854
9855 END IsPreparerToAuditorTransferred;
9856
9857 ----------------------------------------------------------------------
9858 PROCEDURE IsApprovalRequestTransferred(
9859 p_item_type IN VARCHAR2,
9860 p_item_key IN VARCHAR2,
9861 p_actid IN NUMBER,
9862 p_funmode IN VARCHAR2,
9863 p_result OUT NOCOPY VARCHAR2) IS
9864 ----------------------------------------------------------------------
9865
9866 l_debug_info VARCHAR2(1000);
9867
9868 l_notificationID NUMBER;
9869 l_TransferNotificationID NUMBER;
9870 l_TransferToID NUMBER;
9871 l_Transferee wf_users.name%type;
9872 l_TransferToName wf_users.name%type;
9873 l_preparer_id NUMBER;
9874 l_preparer_name wf_users.name%type;
9875 l_preparer_display_name wf_users.display_name%type;
9876 l_AMEEnabled VARCHAR2(1);
9877 l_forwarder AME_UTIL.approverRecord2;
9878 l_forwardee AME_UTIL.approverRecord2;
9879 l_approver_id NUMBER;
9880 l_approver_name varchar2(240);
9881
9882 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
9883 l_entered_by NUMBER := fnd_global.user_id;
9884 l_role_info_tbl wf_directory.wf_local_roles_tbl_type;
9885
9886 l_orig_language_code ap_expense_params.note_language_code%type := null;
9887 l_orig_language fnd_languages.nls_language%type := null;
9888 l_new_language_code ap_expense_params.note_language_code%type := null;
9889 l_new_language fnd_languages.nls_language%type := null;
9890
9891 C_WF_Version NUMBER := 0;
9892
9893 l_itemkey wf_items.item_key%TYPE;
9894 l_approvalProcessCompleteYNOut varchar2(1);
9895 l_nextApproversOut ame_util.approversTable2;
9896 l_ApproverAuthority varchar2(10);
9897 l_oldApproversOut ame_util.approversTable2;
9898
9899 CURSOR c_person_id IS
9900 SELECT orig_system_id
9901 FROM wf_roles
9902 WHERE orig_system = 'PER'
9903 AND name = l_TransferToName;
9904
9905 BEGIN
9906
9907 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start IsApprovalRequestTransferred');
9908
9909 if (p_funmode in ('QUESTION', 'ANSWER')) then
9910
9911 -------------------------------------------------------------------
9912 l_debug_info := 'Need to generate Note based on language setup';
9913 -------------------------------------------------------------------
9914
9915 -------------------------------------------------------------------
9916 l_debug_info := 'Save original language';
9917 -------------------------------------------------------------------
9918 l_orig_language_code := userenv('LANG');
9919 select nls_language
9920 into l_orig_language
9921 from fnd_languages
9922 where language_code = l_orig_language_code;
9923
9924 -------------------------------------------------------------------
9925 l_debug_info := 'Check AP_EXPENSE_PARAMS.NOTE_LANGUAGE_CODE';
9926 -------------------------------------------------------------------
9927 begin
9928 select note_language_code
9929 into l_new_language_code
9930 from ap_expense_params;
9931
9932 exception
9933 when no_data_found then
9934 null;
9935 end;
9936
9937 -------------------------------------------------------------------
9938 l_debug_info := 'Else use instance base language';
9939 -------------------------------------------------------------------
9940 if (l_new_language_code is null) then
9941 select language_code
9942 into l_new_language_code
9943 from fnd_languages
9944 where installed_flag in ('B');
9945 end if;
9946
9947 -------------------------------------------------------------------
9948 l_debug_info := 'Set nls context to new language';
9949 -------------------------------------------------------------------
9950 select nls_language
9951 into l_new_language
9952 from fnd_languages
9953 where language_code = l_new_language_code;
9954
9955 fnd_global.set_nls_context(p_nls_language => l_new_language);
9956
9957 -----------------------------------------
9958 l_debug_info := 'Get the Notification ID';
9959 -----------------------------------------
9960 l_notificationID := wf_engine.context_nid;
9961
9962 ------------------------------------------------------------
9963 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
9964 ------------------------------------------------------------
9965 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
9966 p_item_key,
9967 'EXPENSE_REPORT_ID');
9968
9969 -----------------------------------------
9970 l_debug_info := 'Get the User Id';
9971 -----------------------------------------
9972 begin
9973
9974 WF_DIRECTORY.GetRoleInfo2(wf_engine.context_user, l_role_info_tbl);
9975 AP_WEB_OA_MAINFLOW_PKG.GetUserId(l_role_info_tbl(1).orig_system_id, l_entered_by);
9976
9977 exception
9978 when no_data_found then
9979 null;
9980 end;
9981
9982 ------------------------------------------------------------
9983 l_debug_info := 'store the Request More Info question/answer as a note';
9984 ------------------------------------------------------------
9985 AP_WEB_NOTES_PKG.CreateERPrepToAudNote (
9986 p_report_header_id => l_report_header_id,
9987 p_note => wf_core.translate(p_funmode)||'
9988 '||wf_engine.context_user_comment,
9989 p_lang => l_new_language_code,
9990 p_entered_by => l_entered_by
9991 );
9992
9993 -------------------------------------------------------------------
9994 l_debug_info := 'Restore nls context to original language';
9995 -------------------------------------------------------------------
9996 fnd_global.set_nls_context(p_nls_language => l_orig_language);
9997
9998 elsif (p_funmode in ('TRANSFER','FORWARD')) then
9999 -----------------------------------------
10000 l_debug_info := 'Get the Notification ID';
10001 -----------------------------------------
10002 l_notificationID := wf_engine.context_nid;
10003
10004 -----------------------------------------
10005 l_debug_info := 'Get information on the transfer to';
10006 -----------------------------------------
10007 -- wf_engine.context_text = new responder
10008 l_Transferee := wf_engine.context_text;
10009
10010 -----------------------------------------
10011 l_debug_info := 'check for transferee received through email/web';
10012 -----------------------------------------
10013 IF (substrb(l_Transferee,1,6) = 'email:') THEN
10014 l_TransferToName := substrb(l_Transferee,7);
10015 ELSE
10016 -- response received through web or form
10017 l_TransferToName := l_Transferee;
10018 END IF;
10019
10020 -----------------------------------------
10021 l_debug_info := 'Get the transferee id';
10022 -----------------------------------------
10023 OPEN c_person_id;
10024 FETCH c_person_id into l_TransferToID;
10025 IF c_person_id%NOTFOUND THEN
10026 p_result := wf_engine.eng_completed||':'||wf_engine.eng_null;
10027 Wf_Core.Raise(wf_core.translate('NO_ROLE_FOUND'));
10028 RETURN;
10029 ELSE
10030 IF l_TransferToID IS NULL THEN
10031 p_result := wf_engine.eng_completed||':'||wf_engine.eng_null;
10032 Wf_Core.Raise(wf_core.translate('PERSON_ID_NULL'));
10033 RETURN;
10034 END IF;
10035 END IF;
10036 CLOSE c_person_id;
10037
10038 IF (l_TransferToID IS NOT NULL) THEN
10039 ----------------------------------
10040 l_debug_info := 'Get AME_ENABLED';
10041 ----------------------------------
10042 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
10043 p_item_key,
10044 'AME_ENABLED');
10045
10046 IF (l_AMEEnabled = 'Y') THEN
10047
10048 C_WF_VERSION := GetFlowVersion(p_item_type, p_item_key);
10049 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_R120_Version) THEN
10050 l_itemkey := WF_ENGINE.GetItemAttrText(p_item_type,
10051 p_item_key,
10052 'AME_MASTER_ITEM_KEY');
10053 ELSE
10054 l_itemkey := p_item_key;
10055 END IF;
10056
10057 -- For bug 3062917, if AME is enabled and the approval is forwarded,
10058 -- need to set approval status to ame_util.forwardStatus so the
10059 -- current approver doesn't have to approve again later.
10060
10061 ----------------------------------------------------------------
10062 l_debug_info := 'Retrieving APPROVER_ID Item Attribute';
10063 ----------------------------------------------------------------
10064 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10065 p_item_key,
10066 'APPROVER_ID');
10067
10068 ------------------------------------------------------
10069 l_debug_info := 'Retrieve Approver_ID Item Attribute';
10070 -------------------------------------------------------
10071 l_approver_name := WF_ENGINE.GetItemAttrText(p_item_type,
10072 p_item_key,
10073 'APPROVER_NAME');
10074 ------------------------------------------------------
10075 -- Bug 7272553
10076 l_debug_info := 'Retrieve ApproverAuthority Item Attribute';
10077 -------------------------------------------------------
10078 begin
10079 l_ApproverAuthority := WF_ENGINE.GetItemAttrText(p_item_type,
10080 p_item_key,
10081 'AME_APPROVER_AUTHORITY');
10082 exception
10083 when others then
10084 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
10085 ame_api3.getOldApprovers(
10086 applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
10087 transactionTypeIn => 'APEXP',
10088 transactionIdIn => l_itemkey,
10089 oldApproversOut => l_oldApproversOut);
10090
10091 FOR i IN 1 .. l_oldApproversOut.count LOOP
10092 if l_oldApproversOut(i).orig_system_id = l_approver_id then
10093 l_ApproverAuthority := l_oldApproversOut(i).authority;
10094 exit;
10095 end if;
10096 END LOOP;
10097 else
10098 raise;
10099 end if;
10100 end;
10101
10102 /*
10103 l_forwarder.user_id := null;
10104 l_forwarder.person_id := l_approver_id;
10105 l_forwarder.approval_status := ame_util.forwardStatus;
10106 l_forwarder.authority := ame_util.authorityApprover;
10107
10108 l_forwardee.user_id := null;
10109 l_forwardee.person_id := l_TransferToID;
10110 l_forwardee.api_insertion := ame_util.apiAuthorityInsertion;
10111 l_forwardee.authority := ame_util.authorityApprover;
10112 l_forwardee.approval_status := null;
10113
10114
10115 AME_API.updateApprovalStatus(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
10116 transactionIdIn => p_item_key,
10117 approverIn => l_forwarder,
10118 forwardeeIn => l_forwardee,
10119 transactionTypeIn => p_item_type);
10120 */
10121
10122 l_forwarder.name := l_approver_name;
10123 l_forwarder.approval_status := ame_util.forwardStatus;
10124 l_forwarder.authority := nvl(l_ApproverAuthority,ame_util.authorityApprover);
10125
10126 l_forwardee.name := l_TransferToName;
10127 l_forwardee.authority := nvl(l_ApproverAuthority,ame_util.authorityApprover);
10128 -- Bug 7272553
10129 -- Bug 7463317, altered if condition as suggested by AME dev for vacation rules.
10130 if (l_forwarder.authority = ame_util.authorityApprover and
10131 l_forwarder.api_insertion <> ame_util.apiInsertion) then
10132 l_forwardee.api_insertion := ame_util.apiAuthorityInsertion;
10133 else
10134 l_forwardee.api_insertion := ame_util.apiInsertion;
10135 end if;
10136 l_forwardee.approval_status := null;
10137
10138 AME_API2.updateApprovalStatus(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
10139 transactionTypeIn => p_item_type,
10140 transactionIdIn => l_itemkey,
10141 approverIn => l_forwarder,
10142 forwardeeIn => l_forwardee);
10143
10144 -- 5135505: After re-assign the status of forwardee is null
10145 -- calling getNextApprover[n] will return forwardee and set the status to notified.
10146 begin
10147 AME_API2.getNextApprovers4(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
10148 transactionTypeIn => p_item_type,
10149 transactionIdIn => l_itemkey,
10150 approvalProcessCompleteYNOut => l_approvalProcessCompleteYNOut,
10151 nextApproversOut => l_nextApproversOut);
10152 exception
10153 when others then
10154 null;
10155 end;
10156
10157 END IF;
10158 END IF;
10159
10160 if (p_funmode in ('TRANSFER') OR (l_AMEEnabled = 'Y')) then
10161
10162 -----------------------------------------
10163 l_debug_info := 'set the transferring Approver info to the Transferor';
10164 -----------------------------------------
10165 WF_ENGINE.SetItemAttrText(p_item_type,
10166 p_item_key,
10167 'TRANSFER_APPROVER_DISPLAY_NAME',
10168 WF_ENGINE.GetItemAttrText(p_item_type,
10169 p_item_key,
10170 'APPROVER_DISPLAY_NAME'));
10171
10172 -----------------------------------------------------------
10173 l_debug_info := 'Record the forward from info';
10174 -----------------------------------------------------------
10175 if (l_AMEEnabled = 'Y') then
10176 RecordForwardFromInfo(p_item_type, p_item_key, p_actid, 'TRANSFER', p_result);
10177 else
10178 RecordForwardFromInfo(p_item_type, p_item_key, p_actid, p_funmode, p_result);
10179 end if;
10180
10181 -----------------------------------------
10182 l_debug_info := 'set the current Approver info to the Transferee';
10183 -----------------------------------------
10184 SetPersonAs(l_TransferToID,
10185 p_item_type,
10186 p_item_key,
10187 'APPROVER');
10188
10189 -------------------------------------------------------
10190 l_debug_info := 'Retrieve Preparer_ID Item Attribute';
10191 -------------------------------------------------------
10192 l_preparer_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10193 p_item_key,
10194 'PREPARER_ID');
10195
10196 --Bug 2742114:raise exception when preparer id and trasferee is same.
10197
10198 IF l_preparer_id = l_TransferToID THEN
10199 FND_MESSAGE.SET_NAME('SQLAP','OIE_TRANSFEREE_CANTBE_PREPARER');
10200 app_exception.raise_exception;
10201 END IF;
10202
10203
10204 ----------------------------------------------------------
10205 l_debug_info := 'Get Preparer Name Info For Preparer_Id';
10206 ----------------------------------------------------------
10207 WF_DIRECTORY.GetUserName('PER',
10208 l_preparer_id,
10209 l_preparer_name,
10210 l_preparer_display_name);
10211
10212 /* Bug 3545282 : Set the #FROM_ROLE */
10213 -----------------------------------------------------------
10214 l_debug_info := 'Set the FromRole to the previous approver';
10215 -----------------------------------------------------------
10216
10217 SetFromRoleForwardFrom(p_item_type, p_item_key, p_actid, p_funmode, p_result);
10218
10219 -----------------------------------------
10220 l_debug_info := 'send notification Notify Preparer About Approval Request Transfer';
10221 -----------------------------------------
10222 l_TransferNotificationID := WF_NOTIFICATION.SEND(
10223 role => l_preparer_name,
10224 msg_type => 'APEXP',
10225 msg_name => 'OIE_PREPARER_TRANSFER',
10226 due_date => null,
10227 callback => null,
10228 context => p_item_type||':'||p_item_key||':'||to_char(p_actid),
10229 send_comment => null,
10230 priority => null);
10231
10232 if (l_TransferNotificationID is not null) then
10233 -----------------------------------------
10234 l_debug_info := 'set the notification attributes';
10235 -----------------------------------------
10236 WF_NOTIFICATION.SetAttrText(l_TransferNotificationID,
10237 'DOCUMENT_NUMBER',
10238 WF_ENGINE.GetItemAttrText(p_item_type,
10239 p_item_key,
10240 'DOCUMENT_NUMBER'));
10241
10242 WF_NOTIFICATION.SetAttrText(l_TransferNotificationID,
10243 '#HDR_DISPLAY_TOTAL',
10244 WF_ENGINE.GetItemAttrText(p_item_type,
10245 p_item_key,
10246 'DISPLAY_TOTAL'));
10247 wf_notification.denormalize_notification(l_TransferNotificationID);
10248 end if;
10249
10250 end if;
10251
10252 end if;
10253
10254
10255 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end IsApprovalRequestTransferred');
10256
10257 EXCEPTION
10258 WHEN OTHERS THEN
10259 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsApprovalRequestTransferred',
10260 p_item_type, p_item_key, to_char(0), l_debug_info);
10261 RAISE;
10262
10263 END IsApprovalRequestTransferred;
10264
10265 ----------------------------------------------------------------------
10266 PROCEDURE CheckWFAdminNote(
10267 p_item_type IN VARCHAR2,
10268 p_item_key IN VARCHAR2,
10269 p_actid IN NUMBER,
10270 p_funmode IN VARCHAR2,
10271 p_result OUT NOCOPY VARCHAR2) IS
10272 ----------------------------------------------------------------------
10273
10274 l_debug_info VARCHAR2(1000);
10275
10276 l_notificationID NUMBER;
10277 l_WFAdminNote VARCHAR2(240) := NULL;
10278
10279 BEGIN
10280
10281 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckWFAdminNote');
10282
10283 if (p_funmode = 'RESPOND') then
10284 -----------------------------------------
10285 l_debug_info := 'Get the Notification ID';
10286 -----------------------------------------
10287 l_notificationID := wf_engine.context_nid;
10288
10289 -----------------------------------------
10290 l_debug_info := 'Get WF Admin Note';
10291 -----------------------------------------
10292 l_WFAdminNote := WF_NOTIFICATION.GetAttrText(l_notificationID,
10293 'WF_ADMIN_NOTE');
10294
10295 /* Bug 2798344: The following code does got fire to raise a sql
10296 exception. However, it appears to be a bug than a desired feature.
10297 IF (l_WFAdminNote IS NULL OR replace(l_WFAdminNote, ' ', '') = '') THEN
10298 l_debug_info := 'Please provide specific instructions in the Note field.';
10299 Wf_Core.Raise('ICX_ALL_FIELDS_REQUIRED');
10300 end if;
10301 */
10302 end if;
10303
10304
10305 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckWFAdminNote');
10306
10307 EXCEPTION
10308 WHEN OTHERS THEN
10309 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckWFAdminNote',
10310 p_item_type, p_item_key, to_char(0), l_debug_info);
10311 RAISE;
10312
10313 END CheckWFAdminNote;
10314
10315 ----------------------------------------------------------------------
10316 PROCEDURE SetReturnStatusAndResetAttr(p_item_type IN VARCHAR2,
10317 p_item_key IN VARCHAR2,
10318 p_actid IN NUMBER,
10319 p_funmode IN VARCHAR2,
10320 p_result OUT NOCOPY VARCHAR2) IS
10321 ----------------------------------------------------------------------
10322 l_debug_info VARCHAR2(200);
10323 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
10324 l_payment_due VARCHAR2(10) := C_IndividualPay;
10325 l_No VARCHAR2(1) := 'N';
10326 l_AMEEnabled VARCHAR2(1);
10327 C_WF_Version NUMBER := 0;
10328 l_n_resp_id NUMBER;
10329 BEGIN
10330
10331 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetReturnStatusAndResetAttr');
10332
10333 IF (p_funmode = 'RUN') THEN
10334
10335 -----------------------------------------------------
10336 l_debug_info := 'Get Workflow Version Number';
10337 -----------------------------------------------------
10338 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(p_item_type, p_item_key);
10339
10340 ------------------------------------------------------------
10341 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
10342 ------------------------------------------------------------
10343 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10344 p_item_key,
10345 'EXPENSE_REPORT_ID');
10346
10347 l_AMEEnabled := WF_ENGINE.GetItemAttrText(p_item_type,
10348 p_item_key,
10349 'AME_ENABLED');
10350 IF (l_AMEEnabled = 'Y') THEN
10351
10352 --Bug 4425821: Uptake AME parallel approvers
10353 IF (C_WF_Version >= AP_WEB_EXPENSE_WF.C_R120_Version) THEN
10354 --------------------------------------------
10355 l_debug_info := 'Call AMEAbortRequestApprovals';
10356 --------------------------------------------
10357 AMEAbortRequestApprovals(l_report_header_id);
10358 END IF;
10359
10360 -----------------------------------------
10361 l_debug_info := 'Call clearAllApprovals';
10362 -----------------------------------------
10363 AME_API2.clearAllApprovals(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
10364 transactionIdIn => p_item_key,
10365 transactionTypeIn => p_item_type);
10366 END IF;
10367
10368 ------------------------------------------------------------
10369 l_debug_info := 'Set Returned status in report header';
10370 ------------------------------------------------------------
10371 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(l_report_header_id,
10372 AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_RETURNED,
10373 'NonValidatedWebExpense')) THEN
10374 NULL;
10375 END IF;
10376
10377 --AP_WEB_DB_VIOLATIONS_PKG.deleteViolationEntry(l_report_header_id);
10378 AP_WEB_AUDIT_QUEUE_UTILS.remove_from_queue(l_report_header_id);
10379
10380 ----------------------------------------------------------
10381 l_debug_info := 'Clearing out lines in AP_AUD_AUDIT_REASONS';
10382 ----------------------------------------------------------
10383 -- Bug 4394168
10384 AP_WEB_AUDIT_UTILS.clear_audit_reason_codes(l_report_header_id);
10385
10386
10387 l_payment_due := WF_ENGINE.GetItemAttrText(p_item_type,p_item_key,'PAYMENT_DUE_FROM');
10388
10389 IF (l_payment_due = C_CompanyPay) THEN
10390 IF (NOT AP_WEB_DB_EXPLINE_PKG.DeletePersonalLines(l_report_header_id)) THEN
10391 NULL;
10392 END IF;
10393 END IF;
10394
10395 /* Bug 6502501: cc trxns are detached from expense report when an
10396 expense report is returned.
10397 IF (l_payment_due = C_CompanyPay OR l_payment_due = C_BothPay) THEN
10398 IF (NOT AP_WEB_DB_CCARD_PKG.ResetMgrRejectPersonalTrxns(
10399 l_report_header_id)) THEN
10400 NULL;
10401 END IF;
10402 END IF;
10403 */
10404
10405 -- 4001778/3654956 : reset the Apply Advances
10406 --5060928: reset the Apply Advnaces only if OIE:Enable Advances = "Payables"
10407
10408 begin
10409
10410 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10411 p_item_key,
10412 'RESPONSIBILITY_ID');
10413 exception
10414 when others then
10415 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
10416 null;
10417 else
10418 raise;
10419 end if;
10420 end;
10421
10422 IF FND_PROFILE.VALUE_SPECIFIC('OIE_ENABLE_ADVANCES',NULL,l_n_resp_id,200) = 'PAYABLES' THEN
10423
10424 AP_WEB_DB_EXPLINE_PKG.resetApplyAdvances(l_report_header_id);
10425 END IF;
10426
10427 /* Bug 4019412 */
10428 AP_WEB_DB_EXPLINE_PKG.resetAPflags(l_report_header_id);
10429 ------------------------------------------------------------
10430 l_debug_info := 'Set which process to start from';
10431 ------------------------------------------------------------
10432 -- Indicate which process to start from
10433 -- (skip ServerValidate, Manager Approval)
10434 WF_ENGINE.SetItemAttrText(p_item_type,
10435 p_item_key,
10436 'START_FROM_PROCESS',
10437 C_START_FROM_SERVER_VALIDATION);
10438
10439 -- Reset the attributes which will not be set by code to initialize a
10440 -- process
10441 ------------------------------------------------------------
10442 l_debug_info := 'Reset attribute';
10443 ------------------------------------------------------------
10444 ResetAttrValues(p_item_type, p_item_key, p_actid);
10445
10446 ----------------------------------------------------------
10447 l_debug_info := 'Reset Receipt Verified Flag to N';
10448 ----------------------------------------------------------
10449 -- Bug 4094871
10450 begin
10451 update ap_expense_report_lines
10452 set receipt_verified_flag = l_No
10453 where report_header_id = l_report_header_id;
10454 exception
10455 when others then null;
10456 end;
10457
10458 ------------------------------------------------------------
10459 l_debug_info := 'Raise Receipts Aborted Event';
10460 ------------------------------------------------------------
10461 AP_WEB_RECEIPTS_WF.RaiseAbortedEvent(l_report_header_id);
10462 p_result := 'COMPLETE:Y';
10463
10464 ELSIF (p_funmode = 'CANCEL') THEN
10465 p_result := 'COMPLETE';
10466 END IF;
10467
10468 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetReturnStatusAndResetAttr');
10469
10470 EXCEPTION
10471 WHEN OTHERS THEN
10472 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetReturnStatusAndResetAttr',
10473 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
10474 RAISE;
10475
10476 END SetReturnStatusAndResetAttr;
10477
10478 ----------------------------------------------------------------------
10479 PROCEDURE SetFromRoleBeforeApproval(
10480 p_item_type IN VARCHAR2,
10481 p_item_key IN VARCHAR2,
10482 p_actid IN NUMBER,
10483 p_funmode IN VARCHAR2,
10484 p_result OUT NOCOPY VARCHAR2) IS
10485 ----------------------------------------------------------------------
10486 l_debug_info VARCHAR2(200);
10487 l_find_approver_count NUMBER;
10488 BEGIN
10489
10490 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRoleBeforeApproval');
10491
10492 IF (p_funmode = 'RUN') THEN
10493 ----------------------------------------------------------------
10494 l_debug_info := 'Retrieving Find_Approver_Count Item Attribute';
10495 ----------------------------------------------------------------
10496 l_find_approver_count := WF_ENGINE.GetItemAttrNumber(p_item_type,
10497 p_item_key,
10498 'FIND_APPROVER_COUNT');
10499
10500 IF (l_find_approver_count = 1) THEN
10501 ----------------------------------------------------------------
10502 l_debug_info := 'Set #FROM_ROLE to Preparer';
10503 ----------------------------------------------------------------
10504 SetFromRoleEmployee(p_item_type, p_item_key, p_actid, p_funmode, p_result);
10505 ELSE
10506 ----------------------------------------------------------------
10507 l_debug_info := 'Set #FROM_ROLE to Forward From';
10508 ----------------------------------------------------------------
10509 SetFromRoleForwardFrom(p_item_type, p_item_key, p_actid, p_funmode, p_result);
10510 END IF;
10511
10512 p_result := 'COMPLETE:Y';
10513
10514 ELSIF (p_funmode = 'CANCEL') THEN
10515 p_result := 'COMPLETE';
10516 END IF;
10517
10518 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRoleBeforeApproval');
10519
10520 EXCEPTION
10521 WHEN OTHERS THEN
10522 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRoleBeforeApproval',
10523 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
10524 raise;
10525 END SetFromRoleBeforeApproval;
10526
10527 ----------------------------------------------------------------------
10528 PROCEDURE SetFromRolePreparer(
10529 p_item_type IN VARCHAR2,
10530 p_item_key IN VARCHAR2,
10531 p_actid IN NUMBER,
10532 p_funmode IN VARCHAR2,
10533 p_result OUT NOCOPY VARCHAR2) IS
10534 ----------------------------------------------------------------------
10535 l_debug_info VARCHAR2(200);
10536 BEGIN
10537
10538 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRolePreparer');
10539
10540 IF (p_funmode = 'RUN') THEN
10541 ----------------------------------------------------------------
10542 l_debug_info := 'Set #FROM_ROLE to Preparer';
10543 ----------------------------------------------------------------
10544 SetFromRole(p_item_type,
10545 p_item_key,
10546 p_actid,
10547 WF_ENGINE.GetItemAttrText(p_item_type,
10548 p_item_key,
10549 'PREPARER_NAME'),
10550 'SetFromRolePreparer'
10551 );
10552 /*
10553 WF_ENGINE.SetItemAttrText(p_item_type,
10554 p_item_key,
10555 '#FROM_ROLE',
10556 WF_ENGINE.GetItemAttrText(p_item_type,
10557 p_item_key,
10558 'PREPARER_NAME'));
10559 */
10560 p_result := 'COMPLETE:Y';
10561
10562 ELSIF (p_funmode = 'CANCEL') THEN
10563 p_result := 'COMPLETE';
10564 END IF;
10565
10566 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRolePreparer');
10567
10568 EXCEPTION
10569 WHEN OTHERS THEN
10570 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRolePreparer',
10571 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
10572 raise;
10573 END SetFromRolePreparer;
10574
10575 ----------------------------------------------------------------------
10576 PROCEDURE SetFromRoleEmployee(
10577 p_item_type IN VARCHAR2,
10578 p_item_key IN VARCHAR2,
10579 p_actid IN NUMBER,
10580 p_funmode IN VARCHAR2,
10581 p_result OUT NOCOPY VARCHAR2) IS
10582 ----------------------------------------------------------------------
10583 l_debug_info VARCHAR2(200);
10584 BEGIN
10585
10586 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRoleEmployee');
10587
10588 IF (p_funmode = 'RUN') THEN
10589 ----------------------------------------------------------------
10590 l_debug_info := 'Set #FROM_ROLE to Employee';
10591 ----------------------------------------------------------------
10592 SetFromRole(p_item_type,
10593 p_item_key,
10594 p_actid,
10595 WF_ENGINE.GetItemAttrText(p_item_type,
10596 p_item_key,
10597 'EMPLOYEE_NAME'),
10598 'SetFromRoleEmployee'
10599 );
10600 /*
10601 WF_ENGINE.SetItemAttrText(p_item_type,
10602 p_item_key,
10603 '#FROM_ROLE',
10604 WF_ENGINE.GetItemAttrText(p_item_type,
10605 p_item_key,
10606 'EMPLOYEE_NAME'));
10607 */
10608 p_result := 'COMPLETE:Y';
10609
10610 ELSIF (p_funmode = 'CANCEL') THEN
10611 p_result := 'COMPLETE';
10612 END IF;
10613
10614 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRoleEmployee');
10615
10616 EXCEPTION
10617 WHEN OTHERS THEN
10618 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRoleEmployee',
10619 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
10620 raise;
10621 END SetFromRoleEmployee;
10622
10623 ----------------------------------------------------------------------
10624 PROCEDURE SetFromRoleForwardFrom(
10625 p_item_type IN VARCHAR2,
10626 p_item_key IN VARCHAR2,
10627 p_actid IN NUMBER,
10628 p_funmode IN VARCHAR2,
10629 p_result OUT NOCOPY VARCHAR2) IS
10630 ----------------------------------------------------------------------
10631 l_debug_info VARCHAR2(200);
10632 BEGIN
10633
10634 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRoleForwardFrom');
10635
10636 IF (p_funmode in ('RUN', 'TRANSFER')) THEN
10637 ----------------------------------------------------------------
10638 l_debug_info := 'Set #FROM_ROLE to Forward From';
10639 ----------------------------------------------------------------
10640 SetFromRole(p_item_type,
10641 p_item_key,
10642 p_actid,
10643 WF_ENGINE.GetItemAttrText(p_item_type,
10644 p_item_key,
10645 'FORWARD_FROM_NAME'),
10646 'SetFromRoleForwardFrom'
10647 );
10648 /*
10649 WF_ENGINE.SetItemAttrText(p_item_type,
10650 p_item_key,
10651 '#FROM_ROLE',
10652 WF_ENGINE.GetItemAttrText(p_item_type,
10653 p_item_key,
10654 'FORWARD_FROM_NAME'));
10655 */
10656 p_result := 'COMPLETE:Y';
10657
10658 ELSIF (p_funmode = 'CANCEL') THEN
10659 p_result := 'COMPLETE';
10660 END IF;
10661
10662 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRoleForwardFrom');
10663
10664 EXCEPTION
10665 WHEN OTHERS THEN
10666 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRoleForwardFrom',
10667 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
10668 raise;
10669 END SetFromRoleForwardFrom;
10670
10671 ----------------------------------------------------------------------
10672 PROCEDURE SetFromRoleApprover(
10673 p_item_type IN VARCHAR2,
10674 p_item_key IN VARCHAR2,
10675 p_actid IN NUMBER,
10676 p_funmode IN VARCHAR2,
10677 p_result OUT NOCOPY VARCHAR2) IS
10678 ----------------------------------------------------------------------
10679 l_debug_info VARCHAR2(200);
10680 BEGIN
10681
10682 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRoleApprover');
10683
10684 IF (p_funmode = 'RUN') THEN
10685 ----------------------------------------------------------------
10686 l_debug_info := 'Set #FROM_ROLE to Approver';
10687 ----------------------------------------------------------------
10688 SetFromRole(p_item_type,
10689 p_item_key,
10690 p_actid,
10691 WF_ENGINE.GetItemAttrText(p_item_type,
10692 p_item_key,
10693 'APPROVER_NAME'),
10694 'SetFromRoleApprover'
10695 );
10696 /*
10697 WF_ENGINE.SetItemAttrText(p_item_type,
10698 p_item_key,
10699 '#FROM_ROLE',
10700 WF_ENGINE.GetItemAttrText(p_item_type,
10701 p_item_key,
10702 'APPROVER_NAME'));
10703 */
10704 p_result := 'COMPLETE:Y';
10705
10706 ELSIF (p_funmode = 'CANCEL') THEN
10707 p_result := 'COMPLETE';
10708 END IF;
10709
10710 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRoleApprover');
10711
10712 EXCEPTION
10713 WHEN OTHERS THEN
10714 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRoleApprover',
10715 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
10716 raise;
10717 END SetFromRoleApprover;
10718
10719 ----------------------------------------------------------------------
10720 PROCEDURE SetStatusApproverAndDate(p_item_type IN VARCHAR2,
10721 p_item_key IN VARCHAR2,
10722 p_actid IN NUMBER,
10723 p_funmode IN VARCHAR2,
10724 p_result OUT NOCOPY VARCHAR2) IS
10725 ----------------------------------------------------------------------
10726 l_current_approver_id NUMBER := NULL;
10727 l_expense_status_code VARCHAR2(30) := NULL;
10728 l_date_reset VARCHAR2(30) := NULL;
10729
10730 fixable_exception EXCEPTION;
10731 l_error_message VARCHAR2(2000);
10732 l_debug_info VARCHAR2(200);
10733 l_source VARCHAR2(25) := NULL;
10734 l_holds_setup VARCHAR2(2);
10735 l_report_submitted_date DATE;
10736 l_org_id NUMBER;
10737 l_report_header_id NUMBER;
10738
10739 BEGIN
10740
10741 IF (p_funmode = 'RUN') THEN
10742
10743 -------------------------------------------------------------------
10744 l_debug_info := 'Retrieve Expense Status Code Activity Attribute';
10745 -------------------------------------------------------------------
10746 l_expense_status_code := WF_ENGINE.GetActivityAttrText(p_item_type,
10747 p_item_key,
10748 p_actid,
10749 'EXPENSE_STATUS_CODE');
10750
10751 -------------------------------------------------------------------
10752 l_debug_info := 'Retrieve Current Approver ID Activity Attribute';
10753 -------------------------------------------------------------------
10754 l_current_approver_id := WF_ENGINE.GetActivityAttrNumber(p_item_type,
10755 p_item_key,
10756 p_actid,
10757 'CURRENT_APPROVER_ID');
10758
10759 ------------------------------------------------------------
10760 l_debug_info := 'Retrieve ORG_ID Item Attribute';
10761 ------------------------------------------------------------
10762 l_org_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10763 p_item_key,
10764 'ORG_ID');
10765
10766 ------------------------------------------------------------
10767 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
10768 ------------------------------------------------------------
10769 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
10770 p_item_key,
10771 'EXPENSE_REPORT_ID');
10772
10773 ----------------------------------------------------------
10774 l_debug_info := 'Get Expense Report data';
10775 ----------------------------------------------------------
10776 select report_submitted_date
10777 into l_report_submitted_date
10778 from ap_expense_report_headers
10779 where report_header_id = l_report_header_id;
10780
10781 IF (l_expense_status_code = 'INVOICED') THEN
10782
10783 l_source := 'SelfService';
10784
10785 l_holds_setup := AP_WEB_HOLDS_WF.IsHoldsRuleSetup(l_org_id,
10786 l_report_submitted_date);
10787
10788 IF (l_holds_setup = 'Y') THEN
10789 l_expense_status_code := AP_WEB_RECEIPTS_WF.C_PENDING_HOLDS;
10790 END IF;
10791
10792 END IF;
10793
10794 --Bug 4425821: Uptake AME parallel approvers
10795 -- replaced p_item_key with the l_report_header_id
10796 -------------------------------------------------------------------
10797 l_debug_info := 'Set Expense Status Code and Current Approver ID';
10798 -------------------------------------------------------------------
10799 UPDATE ap_expense_report_headers_all
10800 SET expense_status_code = l_expense_status_code,
10801 expense_current_approver_id = l_current_approver_id,
10802 expense_last_status_date=sysdate,
10803 source = nvl(l_source, source)
10804 WHERE report_header_id = l_report_header_id;
10805
10806 p_result := 'COMPLETE:Y';
10807
10808 ELSIF (p_funmode = 'CANCEL') THEN
10809 NULL;
10810 END IF;
10811
10812 EXCEPTION
10813 WHEN fixable_exception THEN
10814 WF_ENGINE.SetItemAttrText(p_item_type,
10815 p_item_key,
10816 'ERROR_MESSAGE',
10817 l_error_message);
10818
10819 p_result := 'COMPLETE:N';
10820 WHEN OTHERS THEN
10821 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetStatusApproverAndDate',
10822 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
10823 raise;
10824 END SetStatusApproverAndDate;
10825
10826 ---------------------------------------------------------
10827 PROCEDURE ZeroFindApproverCount(p_item_type IN VARCHAR2,
10828 p_item_key IN VARCHAR2,
10829 p_actid IN NUMBER,
10830 p_funmode IN VARCHAR2,
10831 p_result OUT NOCOPY VARCHAR2) IS
10832 ---------------------------------------------------------
10833 l_find_approver_count NUMBER;
10834 l_debug_info VARCHAR2(200);
10835 BEGIN
10836
10837 IF (p_funmode = 'RUN') THEN
10838
10839 ----------------------------------------------------------------
10840 l_debug_info := 'Retrieving Find_Approver_Count Item Attribute';
10841 ----------------------------------------------------------------
10842 l_find_approver_count := WF_ENGINE.GetItemAttrNumber(p_item_type,
10843 p_item_key,
10844 'FIND_APPROVER_COUNT');
10845
10846 IF (l_find_approver_count = 0) THEN
10847 -----------------------------------------------
10848 -- return yes when find_approver_count equals 0
10849 -----------------------------------------------
10850 p_result := 'COMPLETE:Y';
10851 ELSE
10852 ---------------------------------------------------
10853 -- return no if find_approver_count doesn't equal 0
10854 ---------------------------------------------------
10855 p_result := 'COMPLETE:N';
10856 END IF;
10857
10858 ELSIF (p_funmode = 'CANCEL') THEN
10859
10860 p_result := 'COMPLETE';
10861
10862 END IF;
10863
10864 EXCEPTION
10865 WHEN OTHERS THEN
10866 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ZeroFindApproverCount',
10867 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
10868 raise;
10869 END ZeroFindApproverCount;
10870
10871 /*----------------------------------------------------------------------------*
10872 | Procedure |
10873 | WithdrawExpenseRep |
10874 | |
10875 | DESCRIPTION |
10876 | Withdraw the expense report from workflow approval |
10877 | bug1552747
10878 | PARAMETERS |
10879 | INPUT |
10880 | p_employee_id NUMBER -- Expense Report Header ID |
10881 | RETURNS |
10882 | none |
10883 *----------------------------------------------------------------------------*/
10884
10885 PROCEDURE WithdrawExpenseRep(
10886 p_rep_header_id IN AP_EXPENSE_REPORT_LINES.report_header_id%TYPE)
10887 IS
10888 l_itemkey wf_items.item_key%TYPE;
10889 l_itemtype wf_items.item_type%TYPE := 'APEXP';
10890 l_document_number AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
10891 l_doc_cctr VARCHAR2(2000);
10892 l_preparer_name VARCHAR2(2000);
10893 l_employee_name VARCHAR2(2000);
10894 l_purpose VARCHAR2(2400);
10895 l_payable_admin wf_notifications.recipient_role%TYPE;
10896 l_currency VARCHAR2(50);
10897 l_total VARCHAR2(200);
10898 l_payment_due VARCHAR2(100);
10899 l_debug_info VARCHAR2(200);
10900 l_wf_active BOOLEAN := FALSE;
10901 l_wf_exist BOOLEAN := FALSE;
10902 l_end_date wf_items.end_date%TYPE;
10903 l_AMEEnabled VARCHAR2(1);
10904 l_receipts_status VARCHAR2(30);
10905
10906 l_entered_by NUMBER := fnd_global.user_id;
10907 l_note varchar2(2000);
10908 l_message_name fnd_new_messages.message_name%type := 'OIE_WITHDRAWN_NOTE';
10909
10910 l_orig_language_code ap_expense_params.note_language_code%type := null;
10911 l_orig_language fnd_languages.nls_language%type := null;
10912 l_new_language_code ap_expense_params.note_language_code%type := null;
10913 l_new_language fnd_languages.nls_language%type := null;
10914
10915 l_No VARCHAR2(1) := 'N';
10916 C_WF_Version NUMBER := 0;
10917 l_n_resp_id NUMBER;
10918 BEGIN
10919
10920 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF',
10921 'start WF WithdrawExpenseRep');
10922
10923 l_itemkey := to_char(p_rep_header_id);
10924 begin
10925 select end_date
10926 into l_end_date
10927 from wf_items
10928 where item_type = l_itemtype
10929 and item_key = l_itemkey;
10930
10931 if l_end_date is NULL then
10932 l_wf_active := TRUE;
10933 else
10934 l_wf_active := FALSE;
10935 end if;
10936 l_wf_exist := TRUE;
10937 exception
10938 when no_data_found then
10939 l_wf_active := FALSE;
10940 l_wf_exist := FALSE;
10941 end;
10942
10943 -----------------------------------------------------
10944 l_debug_info := 'Get Workflow Version Number';
10945 -----------------------------------------------------
10946 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(l_itemtype, l_itemkey);
10947
10948 if l_wf_exist then
10949 l_debug_info := 'Get Attribute values';
10950 l_preparer_name := WF_ENGINE.GetItemAttrText(
10951 itemtype => l_itemtype,
10952 itemkey => l_itemkey,
10953 aname => 'PREPARER_DISPLAY_NAME');
10954 l_employee_name := WF_ENGINE.GetItemAttrText(
10955 itemtype => l_itemtype,
10956 itemkey => l_itemkey,
10957 aname => 'EMPLOYEE_DISPLAY_NAME');
10958 l_document_number := WF_ENGINE.GetItemAttrText(
10959 itemtype => l_itemtype,
10960 itemkey => l_itemkey,
10961 aname => 'DOCUMENT_NUMBER');
10962 l_payable_admin := WF_ENGINE.GetItemAttrText(
10963 itemtype => l_itemtype,
10964 itemkey => l_itemkey,
10965 aname => 'PAYABLES');
10966 l_total := WF_ENGINE.GetItemAttrText(
10967 itemtype => l_itemtype,
10968 itemkey => l_itemkey,
10969 aname => 'DISPLAY_TOTAL');
10970 l_currency := WF_ENGINE.GetItemAttrText(
10971 itemtype => l_itemtype,
10972 itemkey => l_itemkey,
10973 aname => 'CURRENCY');
10974 l_doc_cctr := WF_ENGINE.GetItemAttrText(
10975 itemtype => l_itemtype,
10976 itemkey => l_itemkey,
10977 aname => 'DOC_COST_CENTER');
10978 l_purpose := WF_ENGINE.GetItemAttrText(
10979 itemtype => l_itemtype,
10980 itemkey => l_itemkey,
10981 aname => 'PURPOSE');
10982
10983 end if;
10984
10985 l_debug_info := 'Update AME as if rejected';
10986 -- Bug 3560082 - Comment the call to SetRejectStatusInAME and add the call
10987 -- AME_API.clearAllApprovals
10988 l_AMEEnabled := WF_ENGINE.GetItemAttrText(l_itemtype,
10989 l_itemkey,
10990 'AME_ENABLED');
10991 if (l_AMEEnabled = 'Y') then
10992 --Bug 4425821: Uptake AME parallel approvers
10993 if (C_WF_Version >= AP_WEB_EXPENSE_WF.C_R120_Version) then
10994 --------------------------------------------
10995 l_debug_info := 'Call AMEAbortRequestApprovals';
10996 --------------------------------------------
10997 AMEAbortRequestApprovals(p_rep_header_id);
10998 end if;
10999
11000 -----------------------------------------
11001 l_debug_info := 'Call clearAllApprovals';
11002 -----------------------------------------
11003 AME_API2.clearAllApprovals(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
11004 transactionIdIn => l_itemkey,
11005 transactionTypeIn => l_itemtype);
11006 end if;
11007
11008 l_debug_info := 'Set withdraw status in report header';
11009 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(p_rep_header_id,
11010 AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_WITHDRAW,
11011 'NonValidatedWebExpense')) THEN
11012 NULL;
11013 END IF;
11014
11015 AP_WEB_DB_EXPLINE_PKG.resetAPflags(p_rep_header_id);
11016 -- 4001778/3654956
11017 --5060928: reset the Apply Advnaces only if OIE:Enable Advances = "Payables"
11018
11019 begin
11020
11021 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
11022 l_itemkey,
11023 'RESPONSIBILITY_ID');
11024
11025 exception
11026 when others then
11027 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
11028 null;
11029 else
11030 raise;
11031 end if;
11032 end;
11033
11034 IF FND_PROFILE.VALUE_SPECIFIC('OIE_ENABLE_ADVANCES',NULL,l_n_resp_id,200) = 'PAYABLES' THEN
11035
11036 AP_WEB_DB_EXPLINE_PKG.resetApplyAdvances(p_rep_header_id);
11037 END IF;
11038
11039 --AP_WEB_DB_VIOLATIONS_PKG.deleteViolationEntry(p_rep_header_id);
11040 AP_WEB_AUDIT_QUEUE_UTILS.remove_from_queue(p_rep_header_id);
11041
11042 ----------------------------------------------------------
11043 l_debug_info := 'Reset Report Submitted Date to null And Expense Status Code to WITHDRAWN';
11044 ----------------------------------------------------------
11045 -- Bug 4070441
11046 begin
11047 update ap_expense_report_headers
11048 set report_submitted_date = null,
11049 expense_status_code = AP_WEB_OA_ACTIVE_PKG.C_WITHDRAWN
11050 where report_header_id = p_rep_header_id;
11051 exception
11052 when others then null;
11053 end;
11054
11055 ----------------------------------------------------------
11056 l_debug_info := 'Reset Receipt Verified Flag to N';
11057 ----------------------------------------------------------
11058 -- Bug 4094871
11059 begin
11060 update ap_expense_report_lines
11061 set receipt_verified_flag = l_No
11062 where report_header_id = p_rep_header_id;
11063 exception
11064 when others then null;
11065 end;
11066
11067 ----------------------------------------------------------
11068 l_debug_info := 'Clearing out lines in AP_AUD_AUDIT_REASONS';
11069 ----------------------------------------------------------
11070 -- Bug 4394168
11071 AP_WEB_AUDIT_UTILS.clear_audit_reason_codes(p_rep_header_id);
11072
11073 if l_wf_exist then
11074 l_debug_info := 'call reset credit card transactions 2';
11075 ResetCCardTxns(p_rep_header_id, l_itemtype, l_itemkey);
11076
11077 if l_wf_active then
11078 l_debug_info := 'Workflow Abort Process';
11079 wf_engine.AbortProcess (itemtype => l_itemtype,
11080 itemkey => l_itemkey,
11081 cascade => TRUE);
11082 end if;
11083
11084 l_debug_info := 'Purge workflow';
11085 wf_purge.Items(itemtype => l_itemtype,
11086 itemkey => l_itemkey);
11087
11088 /* Bug 3772025 : Calling wf_purge.TotalPerm to purge workflow with persistence type
11089 as 'Permanent'.
11090 */
11091
11092 wf_purge.TotalPerm(itemtype => l_itemtype,
11093 itemkey => l_itemkey,
11094 runtimeonly => TRUE);
11095
11096 end if;
11097
11098 -------------------------------------------------------------------
11099 l_debug_info := 'Save original language';
11100 -------------------------------------------------------------------
11101 l_orig_language_code := userenv('LANG');
11102 select nls_language
11103 into l_orig_language
11104 from fnd_languages
11105 where language_code = l_orig_language_code;
11106
11107 -------------------------------------------------------------------
11108 l_debug_info := 'Check AP_EXPENSE_PARAMS.NOTE_LANGUAGE_CODE';
11109 -------------------------------------------------------------------
11110 begin
11111 select note_language_code
11112 into l_new_language_code
11113 from ap_expense_params;
11114
11115 exception
11116 when no_data_found then
11117 null;
11118 end;
11119
11120 -------------------------------------------------------------------
11121 l_debug_info := 'Else use instance base language';
11122 -------------------------------------------------------------------
11123 if (l_new_language_code is null) then
11124 select language_code
11125 into l_new_language_code
11126 from fnd_languages
11127 where installed_flag in ('B');
11128 end if;
11129
11130 -------------------------------------------------------------------
11131 l_debug_info := 'Set nls context to new language';
11132 -------------------------------------------------------------------
11133 select nls_language
11134 into l_new_language
11135 from fnd_languages
11136 where language_code = l_new_language_code;
11137
11138 fnd_global.set_nls_context(p_nls_language => l_new_language);
11139
11140 begin
11141 -------------------------------------------------------------------
11142 -- fnd_global.set_nls_context() seems to work for WF but not FND_MESSAGES
11143 -------------------------------------------------------------------
11144 select message_text
11145 into l_note
11146 from fnd_new_messages
11147 where application_id = 200
11148 and message_name = l_message_name
11149 and language_code = l_new_language_code;
11150
11151 exception
11152 when no_data_found then
11153 FND_MESSAGE.SET_NAME('SQLAP', l_message_name);
11154 l_note := FND_MESSAGE.GET;
11155 end;
11156
11157 ------------------------------------------------------------
11158 l_debug_info := 'store the withdrawn note';
11159 ------------------------------------------------------------
11160 AP_WEB_NOTES_PKG.CreateERPrepToAudNote (
11161 p_report_header_id => p_rep_header_id,
11162 p_note => l_note,
11163 p_lang => l_new_language_code
11164 );
11165
11166 -------------------------------------------------------------------
11167 l_debug_info := 'Restore nls context to original language';
11168 -------------------------------------------------------------------
11169 fnd_global.set_nls_context(p_nls_language => l_orig_language);
11170
11171 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF',
11172 'end WF WithdrawExpenseRep');
11173 COMMIT;
11174
11175 ------------------------------------------------------------
11176 l_debug_info := 'Raise Receipts Aborted Event';
11177 ------------------------------------------------------------
11178 AP_WEB_RECEIPTS_WF.RaiseAbortedEvent(p_rep_header_id);
11179
11180 COMMIT;
11181
11182
11183 EXCEPTION
11184 WHEN OTHERS THEN
11185 ROLLBACK;
11186 APP_EXCEPTION.RAISE_EXCEPTION;
11187 END WithdrawExpenseRep;
11188
11189
11190 PROCEDURE GenerateExpClobLines(document_id IN VARCHAR2,
11191 display_type IN VARCHAR2,
11192 document IN OUT NOCOPY CLOB,
11193 document_type IN OUT NOCOPY VARCHAR2) IS
11194
11195 l_colon NUMBER;
11196 l_itemtype VARCHAR2(7);
11197 l_itemkey VARCHAR2(25);
11198
11199 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
11200 l_receipt_missing_flag AP_WEB_DB_EXPLINE_PKG.expLines_receiptMissingFlag;
11201 l_start_date AP_WEB_DB_EXPLINE_PKG.expLines_startExpDate;
11202 l_days VARCHAR2(4);
11203 l_daily_amt AP_WEB_DB_EXPLINE_PKG.expLines_dailyAmount;
11204 l_receipt_curr AP_WEB_DB_EXPLINE_PKG.expLines_receiptCurrCode;
11205 l_receipt_rate VARCHAR2(5);
11206 l_receipt_amt VARCHAR2(10);
11207 l_total_amt AP_WEB_DB_EXPLINE_PKG.expLines_amount;
11208 l_expense_report_total_amt AP_WEB_DB_EXPLINE_PKG.expLines_amount;
11209 l_cc_personal_total_amt AP_WEB_DB_EXPLINE_PKG.expLines_amount;
11210 l_justification AP_WEB_DB_EXPLINE_PKG.expLines_justification;
11211 l_expense_type AP_WEB_DB_EXPTEMPLATE_PKG.expTempl_webFriendlyPrompt;
11212 l_project_number PA_PROJECTS.segment1%TYPE;
11213 l_task_number AP_WEB_DB_PA_INT_PKG.tasks_taskNum;
11214 l_award_number GMS_OIE_INT_PKG.gms_awardNum;
11215 l_credit_card_trx_id AP_WEB_DB_EXPLINE_PKG.expLines_crdCardTrxID;
11216 l_distribution_line_number AP_WEB_DB_EXPLINE_PKG.expLines_distLineNum;
11217 l_line_number NUMBER := 0;
11218 l_primary_number NUMBER := 1;
11219 l_line_display VARCHAR2(5);
11220 l_counter NUMBER := 1;
11221 l_violation_type AP_LOOKUP_CODES.DISPLAYED_FIELD%TYPE;
11222 l_employee_project_enabled VARCHAR2(1);
11223 -- Grants Integration
11224 l_grants_enabled VARCHAR2(1) := 'N';
11225 l_project_string VARCHAR2(100);
11226 l_line_info VARCHAR2(2000);
11227 l_num_lines NUMBER := 0;
11228 l_num_cc_lines NUMBER := 0;
11229 l_num_personal_lines NUMBER := 0;
11230 l_num_cash_lines NUMBER := 0;
11231 l_table_loop_counter NUMBER := 0;
11232 l_document_max NUMBER := 25000; -- 27721 fails
11233 l_is_cc_table BOOLEAN;
11234 l_currency VARCHAR2(50);
11235 l_colspan NUMBER := 0;
11236
11237 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
11238 l_title AK_REGIONS_VL.name%TYPE;
11239 l_debug_info VARCHAR2(1000);
11240
11241 XpenseLinesCursor AP_WEB_DB_EXPLINE_PKG.DisplayXpenseLinesCursor;
11242 PersonalLinesCursor AP_WEB_DB_EXPLINE_PKG.DisplayXpenseLinesCursor;
11243
11244 --Bug 2944363
11245 BothPayPersonalLinesCursor AP_WEB_DB_EXPLINE_PKG.DisplayXpenseLinesCursor;
11246
11247
11248 l_n_org_id Number;
11249
11250 l_show_message VARCHAR2(1) := 'N';
11251 l_message VARCHAR2(2000);
11252 l_rules_violated VARCHAR2(1) := 'N';
11253 l_last_dist_number AP_WEB_DB_EXPLINE_PKG.expLines_distLineNum
11254 := -1;
11255
11256 l_document long;
11257
11258 l_flex_concatenated AP_EXPENSE_REPORT_LINES.flex_concatenated%TYPE;
11259 l_line_accounting_enabled VARCHAR2(30);
11260 l_line_accounting_defined BOOLEAN;
11261 l_policy_violation_value VARCHAR2(50);
11262 l_policy_violation_defined BOOLEAN;
11263 l_n_resp_id Number;
11264 l_mrate_adjusted_flag AP_EXPENSE_REPORT_LINES.mileage_rate_adjusted_flag%TYPE;
11265 l_mileage_note VARCHAR2(2000);
11266 l_notification_type VARCHAR2(10);
11267 l_print_violation VARCHAR2(1) := 'N';
11268 l_merchant_name AP_EXPENSE_REPORT_LINES.merchant_name%TYPE;
11269 l_co_merchant_count NUMBER;
11270
11271 l_num_both_personal_lines NUMBER := 0; --Bug 2944363
11272 l_payment VARCHAR2(10);--Bug 2944363
11273 l_cc_trxn_date VARCHAR2(50);--Bug 2944363
11274 l_cc_expensed_amt AP_WEB_DB_EXPLINE_PKG.expLines_amount;--Bug 2944363
11275 l_cc_curr_code VARCHAR2(20); --Bug 2944363
11276 l_cc_merchant_name AP_CREDIT_CARD_TRXNS_ALL.merchant_name1%TYPE;--Bug 2944363
11277 l_payment_due_from VARCHAR2(10) := 'INDIVIDUAL';
11278
11279 BEGIN
11280
11281 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateExpClobLines');
11282
11283 ------------------------------------------------------------
11284 l_debug_info := 'Decode document_id';
11285 ------------------------------------------------------------
11286 l_colon := instrb(document_id, ':');
11287 l_debug_info := ' First index: ' || to_char(l_colon);
11288 l_itemtype := substrb(document_id, 1, l_colon - 1);
11289 l_itemkey := substrb(document_id, l_colon + 1);
11290 l_colon := instrb(l_itemkey, ':');
11291
11292 ------------------------------------------------------------
11293 l_debug_info := 'Second index: ' || to_char(l_colon);
11294 ------------------------------------------------------------
11295 IF (l_colon > 0) THEN
11296 l_notification_type := substrb(l_itemkey, l_colon + 1);
11297 l_itemkey := substrb(l_itemkey, 1, l_colon - 1);
11298 ELSE
11299 l_notification_type := C_OTHER;
11300 END IF;
11301
11302 ------------------------------------------------------------
11303 l_debug_info := 'Get prompts';
11304 ------------------------------------------------------------
11305 AP_WEB_DISC_PKG.getPrompts(200,'AP_WEB_WF_LINETABLE',l_title,l_prompts);
11306
11307 ------------------------------------------------------------
11308 l_debug_info := 'Check Projects enabled';
11309 ------------------------------------------------------------
11310 l_employee_project_enabled := WF_ENGINE.GetItemAttrText(l_itemtype,
11311 l_itemkey,
11312 'EMPLOYEE_PROJECT_ENABLED');
11313
11314 ------------------------------------------------------------
11315 l_debug_info := 'Check Grants enabled';
11316 ------------------------------------------------------------
11317 begin
11318 l_grants_enabled := WF_ENGINE.GetItemAttrText(l_itemtype,
11319 l_itemkey,
11320 'GRANTS_ENABLED');
11321
11322 ------------------------------------------------------------
11323 l_debug_info := 'Get responsibility id';
11324 ------------------------------------------------------------
11325 l_n_resp_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
11326 l_itemkey,
11327 'RESPONSIBILITY_ID');
11328
11329 exception
11330 when others then
11331 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
11332 null;
11333 else
11334 raise;
11335 end if;
11336 end;
11337
11338 ------------------------------------------------------------
11339 l_debug_info := 'Check line level accounting enabled';
11340 ------------------------------------------------------------
11341 FND_PROFILE.get_specific('OIE_ENABLE_LINE_LEVEL_ACCOUNTING', null,
11342 l_n_resp_id, 200, l_line_accounting_enabled, l_line_accounting_defined);
11343
11344
11345 if l_line_accounting_defined then
11346 l_line_accounting_enabled := NVL(l_line_accounting_enabled,'N');
11347 else
11348 l_line_accounting_enabled := 'N';
11349 end if;
11350
11351 ------------------------------------------------------------
11352 l_debug_info := 'Get policy profile option';
11353 ------------------------------------------------------------
11354 FND_PROFILE.get_specific('AP_WEB_POLICY_VIOLATION_SUBMIT', null,
11355 l_n_resp_id, 200, l_policy_violation_value, l_policy_violation_defined);
11356
11357 if l_policy_violation_defined then
11358 l_policy_violation_value := NVL(l_policy_violation_value, C_ALLOW_NO_WARNINGS);
11359 else
11360 l_policy_violation_value := C_ALLOW_NO_WARNINGS;
11361 end if;
11362
11363 ------------------------------------------------------------
11364 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
11365 ------------------------------------------------------------
11366 l_report_header_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
11367 l_itemkey,
11368 'EXPENSE_REPORT_ID');
11369
11370 ------------------------------------------------------------
11371 l_debug_info := 'Retrieve Currency Item Attribute';
11372 ------------------------------------------------------------
11373 l_currency := WF_ENGINE.GetItemAttrText(l_itemtype,
11374 l_itemkey,
11375 'CURRENCY');
11376
11377 ------------------------------------------------------------
11378 l_debug_info := 'Retrieve MILEAGE NOTE Item Attribute';
11379 ------------------------------------------------------------
11380 begin
11381 l_mileage_note := WF_ENGINE.GetItemAttrText(l_itemtype,
11382 l_itemkey,
11383 'MILEAGE_NOTE');
11384 exception
11385 when others then
11386 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
11387 null;
11388 else
11389 raise;
11390 end if;
11391 end;
11392
11393 --------------------------------------------
11394 l_debug_info := 'Get Org Id';
11395 --------------------------------------------
11396 begin
11397
11398 l_n_org_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
11399 l_itemkey,
11400 'ORG_ID');
11401 exception
11402 when others then
11403 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
11404 -- ORG_ID item attribute doesn't exist, need to add it
11405 WF_ENGINE.AddItemAttr(l_itemtype, l_itemkey, 'ORG_ID');
11406 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(
11407 to_number(l_itemkey),
11408 l_n_org_id) <> TRUE ) THEN
11409 l_n_org_id := NULL;
11410 END IF;
11411
11412 WF_ENGINE.SetItemAttrNumber(l_itemtype,
11413 l_itemkey,
11414 'ORG_ID',
11415 l_n_org_ID);
11416 else
11417 raise;
11418 end if;
11419
11420 end;
11421
11422 -- MOAC UPTAKE --
11423 -- Should not have to initialize the org context
11424 -- This is done via callbackfunction()
11425 /*--------------------
11426 if (l_n_org_id is not null) then
11427 fnd_client_info.set_org_context(l_n_org_id);
11428 else
11429 -- Report was submitted before org_id being added, hence org_id
11430 -- item attributes hasn't been set yet. Need to get it from
11431 -- report header
11432 IF (AP_WEB_DB_EXPRPT_PKG.GetOrgIdByReportHeaderId(to_number(l_itemkey), l_n_org_id) <> TRUE ) THEN
11433 l_n_org_id := NULL;
11434 END IF;
11435
11436 IF (l_n_org_id is not null) then
11437 fnd_client_info.set_org_context(l_n_org_id);
11438 END IF;
11439
11440 end if; -- l_n_org_id
11441 --------------------*/
11442
11443 --------------------------------------------
11444 l_debug_info := 'get Number of ExpLines';
11445 --------------------------------------------
11446 if (AP_WEB_DB_EXPLINE_PKG.GetNumberOfExpLines(l_report_header_id, l_num_lines)) then null; end if;
11447
11448 if (l_num_lines = 0) then
11449
11450 /*Bug 2944363: Dont raise SHORTPAID error if the expense report
11451 does not have any lines. raise it conditionally because
11452 an ER in BOTHPAY having only personal CC trx will
11453 also not have any lines.
11454 */
11455 --AMMISHRA - Both Pay Personal Only Lines project.
11456 if (AP_WEB_DB_EXPLINE_PKG.GetNoOfBothPayPersonalLines(l_report_header_id,l_num_both_personal_lines)) then null; end if;
11457
11458 ----------------------------------------------------------------
11459 l_debug_info := 'Retrieve Profile Option Payment Due From';
11460 ----------------------------------------------------------------
11461
11462 IF (NOT AP_WEB_DB_EXPRPT_PKG.getPaymentDueFromReport(to_number(l_itemkey),l_payment)) THEN
11463 l_debug_info := 'Could not set workflow attribute Payment_Due_From';
11464 END IF;
11465
11466 IF (l_payment = 'BOTH' and l_num_both_personal_lines > 0) THEN
11467 NULL;
11468 ELSE
11469 FND_MESSAGE.SET_NAME('SQLAP','AP_WEB_EXP_REPORT_SHORTPAID');
11470 WF_NOTIFICATION.WriteToClob(document,fnd_message.get);
11471 document_type := display_type;
11472 return;
11473 END IF;
11474 --Bug 2944363 End here.
11475
11476 end if;
11477
11478 l_document := '';
11479 if (display_type = 'text/plain') then
11480 l_num_lines := 0;
11481 --------------------------------------------
11482 l_debug_info := 'Generate Table Header';
11483 --------------------------------------------
11484
11485 --------------------------------------------
11486 l_debug_info := 'Open Expense Lines Cursor';
11487 --------------------------------------------
11488 IF (AP_WEB_DB_EXPLINE_PKG.GetDisplayXpenseLinesCursor(l_report_header_id, XpenseLinesCursor)) THEN
11489
11490 LOOP
11491
11492 --------------------------------------------
11493 l_debug_info := 'Fetch Expense Lines Cursor';
11494 --------------------------------------------
11495 FETCH XpenseLinesCursor INTO l_receipt_missing_flag,
11496 l_start_date,
11497 l_days,
11498 l_daily_amt,
11499 l_receipt_curr,
11500 l_receipt_rate,
11501 l_receipt_amt,
11502 l_total_amt,
11503 l_justification,
11504 l_expense_type,
11505 l_project_number,
11506 l_task_number,
11507 l_credit_card_trx_id,
11508 l_distribution_line_number,
11509 l_award_number,
11510 l_violation_type,
11511 l_merchant_name;
11512
11513 EXIT WHEN XpenseLinesCursor%NOTFOUND;
11514
11515 l_num_lines := l_num_lines + 1;
11516
11517 -------------------------------------------------------------------
11518 l_debug_info := 'Check if Receipt missing, print * next to line and set boolean flag';
11519 -------------------------------------------------------------------
11520 IF (l_receipt_missing_flag = 'Y') THEN
11521 l_line_info := ' * ';
11522 ELSE
11523 l_line_info := ' ';
11524 END IF;
11525
11526 --------------------------------------------
11527 l_debug_info := 'Format Expense Line Info';
11528 --------------------------------------------
11529 l_project_string := '';
11530 IF (l_project_number IS NOT NULL) THEN
11531 l_project_string := l_project_number || ' ' || l_task_number;
11532 if (l_grants_enabled = 'Y') then
11533 l_project_string := l_project_string || ' ' || l_award_number;
11534 end if;
11535 END IF;
11536 l_line_info := '(' || to_char(l_num_lines) || ')' || l_line_info || ' '|| l_start_date
11537 || l_expense_type || ' ' || l_project_string
11538 || ' ' || LPAD(to_char(l_total_amt, FND_CURRENCY.Get_Format_Mask(l_currency,22)),14);
11539 -- set a new line
11540 l_document := l_document || '
11541 ';
11542 l_document := l_document || l_line_info;
11543 -- set a new line
11544 l_document := l_document || '
11545 ';
11546 l_document := l_document || '----> ' || l_justification;
11547 l_line_info := '';
11548
11549 END LOOP; -- GetDisplayXpenseLinesCursor
11550
11551 END IF; -- GetDisplayXpenseLinesCursor
11552
11553 if XpenseLinesCursor%isopen then /*Bug 3422298 */
11554 close XpenseLinesCursor;
11555 end if;
11556
11557 else -- text/html
11558
11559 --------------------------------------------
11560 l_debug_info := 'get Number of Cash/Credit Card lines';
11561 --------------------------------------------
11562 if (AP_WEB_DB_EXPLINE_PKG.GetNumCCLinesIncluded(l_report_header_id, l_num_cc_lines)) then null; end if;
11563 l_num_cash_lines := l_num_lines - l_num_cc_lines;
11564
11565
11566 --------------------------------------------
11567 l_debug_info := 'get Number of Cash/Credit Card lines';
11568 --------------------------------------------
11569 if (AP_WEB_DB_EXPLINE_PKG.GetNumCashLinesWOMerch(l_report_header_id, l_co_merchant_count)) then null; end if;
11570
11571 --------------------------------------------
11572 l_debug_info := 'loop thru Cash/Credit Card lines';
11573 --------------------------------------------
11574 for l_table_loop_counter in 1..2
11575 loop
11576
11577 IF lengthb(l_document) >= l_document_max THEN
11578 -- Appends l_document to end of document (CLOB object)
11579 WF_NOTIFICATION.WriteToClob(document,l_document);
11580 l_document := '';
11581 --l_show_message := 'Y';
11582 --exit;
11583 END IF;
11584
11585 l_expense_report_total_amt := 0;
11586 l_num_lines := 0;
11587 l_line_number := 0;
11588 l_primary_number := 1;
11589 l_counter := 1;
11590
11591 if (l_table_loop_counter = 1) then
11592 l_is_cc_table := true;
11593 else
11594 l_is_cc_table := false;
11595 end if;
11596
11597 --------------------------------------------
11598 l_debug_info := 'Traverse selected lines';
11599 --------------------------------------------
11600 if ((l_is_cc_table AND l_num_cc_lines > 0) OR
11601 (NOT l_is_cc_table AND l_num_cash_lines > 0)) then
11602
11603 --------------------------------------------
11604 l_debug_info := 'Generate Table Header';
11605 --------------------------------------------
11606 if l_is_cc_table then
11607 l_document := l_document || indent_start || table_title_start || l_prompts(1) || table_title_end;
11608 else
11609 l_document := l_document || indent_start || table_title_start || l_prompts(2) || table_title_end;
11610 end if;
11611
11612 l_document := l_document || table_start;
11613
11614 l_document := l_document || tr_start;
11615
11616
11617 IF (AP_WEB_DB_EXPLINE_PKG.AnyPolicyViolation(l_report_header_id)) THEN
11618 l_rules_violated := 'Y';
11619 END IF;
11620
11621 /* If the profile option is set to APPROVER_ONLY
11622 (ALLOW_NO_WARNINGS), do not show any violations to the employee
11623 notifications. */
11624 IF (l_rules_violated = 'Y' ) THEN
11625 IF ((l_policy_violation_value = C_ALLOW_NO_WARNINGS) AND
11626 (l_notification_type <> C_EMP)) OR
11627 (l_policy_violation_value <> C_ALLOW_NO_WARNINGS) THEN
11628 l_print_violation := 'Y';
11629 l_document := l_document || th_text || '&' || 'nbsp;' || td_end;
11630 END IF;
11631 END IF;
11632
11633
11634 -- display Line Number
11635 l_document := l_document || th_select || l_prompts(13) || td_end;
11636
11637
11638 IF (l_rules_violated = 'Y' ) THEN
11639 IF ((l_policy_violation_value = C_ALLOW_NO_WARNINGS) AND
11640 (l_notification_type <> C_EMP)) OR
11641 (l_policy_violation_value <> C_ALLOW_NO_WARNINGS) THEN
11642 l_document := l_document || th_text || l_prompts(14) || td_end;
11643 END IF;
11644 END IF;
11645
11646 -- display Date
11647 l_document := l_document || th_text || l_prompts(4) || td_end;
11648 -- display Expense Type
11649 l_document := l_document || th_text || l_prompts(5) || td_end;
11650 -- display Merchant Name
11651 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
11652 l_document := l_document || th_text || l_prompts(27) || td_end;
11653 end if;
11654 if (l_employee_project_enabled = 'Y') then
11655 -- display Project/Task only when Projects enabled
11656 l_document := l_document || th_text || l_prompts(6) || td_end;
11657 l_document := l_document || th_text || l_prompts(7) || td_end;
11658 -- Grants Integration
11659 if (l_grants_enabled = 'Y') then
11660 l_document := l_document || th_text || l_prompts(8) || td_end;
11661 end if;
11662 end if;
11663 -- display Amount
11664 l_document := l_document || th_number || l_prompts(9) || td_end;
11665 -- display Justification
11666 l_document := l_document || th_text || l_prompts(10) || td_end;
11667
11668 if (l_line_accounting_enabled = 'Y') then
11669 l_document := l_document || th_text || l_prompts(15) || td_end;
11670 end if;
11671 l_document := l_document || tr_end;
11672
11673 --------------------------------------------
11674 l_debug_info := 'Open Expense Lines Cursor';
11675 --------------------------------------------
11676 IF (AP_WEB_DB_EXPLINE_PKG.GetDisplayXpenseLinesCursor(l_report_header_id, l_is_cc_table, XpenseLinesCursor)) THEN
11677
11678 LOOP
11679
11680 --------------------------------------------
11681 l_debug_info := 'Fetch Expense Lines Cursor';
11682 --------------------------------------------
11683 FETCH XpenseLinesCursor INTO l_receipt_missing_flag,
11684 l_start_date,
11685 l_days,
11686 l_daily_amt,
11687 l_receipt_curr,
11688 l_receipt_rate,
11689 l_receipt_amt,
11690 l_total_amt,
11691 l_justification,
11692 l_expense_type,
11693 l_project_number,
11694 l_task_number,
11695 l_credit_card_trx_id,
11696 l_distribution_line_number,
11697 l_award_number,
11698 l_violation_type,
11699 l_merchant_name,
11700 l_flex_concatenated,
11701 l_mrate_adjusted_flag;
11702
11703 EXIT WHEN XpenseLinesCursor%NOTFOUND;
11704
11705 IF lengthb(l_document) >= l_document_max THEN
11706 -- Appends l_document to end of document (CLOB object)
11707 WF_NOTIFICATION.WriteToClob(document,l_document);
11708 l_document := '';
11709 --l_show_message := 'Y';
11710 --exit;
11711 END IF;
11712
11713 IF ((l_notification_type = C_EMP) AND
11714 (l_policy_violation_value = C_ALLOW_NO_WARNINGS) AND
11715 (l_distribution_line_number = l_last_dist_number)) THEN
11716 null;
11717 ELSE
11718 l_num_lines := l_num_lines + 1;
11719 l_document := l_document || tr_start;
11720 ------------------------------------------------------------
11721 l_debug_info := 'If policy violated, indicate with a gif';
11722 ------------------------------------------------------------
11723 IF (l_rules_violated = 'Y' ) THEN
11724 IF ((l_policy_violation_value = C_ALLOW_NO_WARNINGS) AND
11725 (l_notification_type <> C_EMP)) OR
11726 (l_policy_violation_value <> C_ALLOW_NO_WARNINGS) THEN
11727 IF (l_violation_type is not null ) THEN
11728 l_document := l_document || td_text || '**' || td_end;
11729 -- Bug 2750863: With WF mailer limitation, images can't be
11730 -- displayed on email notifications. Therefore, taking the
11731 -- image out from the following until the WF issue has been
11732 -- addressed.
11733 --face='||td_fontface||'><img src="/OA_MEDIA/warningicon_status.gif">'||td_end;
11734 ELSE
11735 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
11736 END IF;
11737 END IF;
11738 END IF;
11739
11740 IF l_mileage_note is not null THEN
11741 IF (l_mrate_adjusted_flag is not null) THEN
11742 l_line_info := '* ';
11743 ELSE
11744 l_line_info := '&' || 'nbsp;' || '&' || 'nbsp;';
11745 END IF;
11746
11747 ELSE
11748 ------------------------------------------------------------
11749 l_debug_info := 'If Any Receipts Missing Then Print Warning';
11750 ------------------------------------------------------------
11751 IF (l_receipt_missing_flag = 'Y') THEN
11752 l_line_info := '* ';
11753 ELSE
11754 l_line_info := '&' || 'nbsp;' || '&' || 'nbsp;';
11755 END IF;
11756 END IF;
11757
11758 IF (l_distribution_line_number <> l_last_dist_number) THEN
11759
11760 -- display Line Number
11761 l_document := l_document || td_select;
11762 --l_line_numbr := l_line_number + 1;
11763 l_line_display := l_primary_number;
11764 l_primary_number := l_primary_number + 1;
11765 l_counter := l_counter + 1;
11766 l_document := l_document || l_line_info || ' ' || l_line_display || ' ' || td_end;
11767 ELSE
11768 -- display Line Number
11769 l_document := l_document || td_select;
11770 l_document := l_document || l_line_info || td_end;
11771
11772 END IF;
11773
11774 ------------------------------------------------------------
11775 l_debug_info := 'If policy violated, show the violation type';
11776 ------------------------------------------------------------
11777 IF (l_rules_violated = 'Y' ) THEN
11778 IF ((l_policy_violation_value = C_ALLOW_NO_WARNINGS) AND
11779 (l_notification_type <> C_EMP)) OR
11780 (l_policy_violation_value <> C_ALLOW_NO_WARNINGS) THEN
11781 IF (l_violation_type is not null ) THEN
11782 l_document := l_document || td_text || nvl(l_violation_type, '&' || 'nbsp;') || td_end;
11783 ELSE
11784 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
11785 END IF;
11786 END IF;
11787 END IF;
11788
11789 IF (l_distribution_line_number <> l_last_dist_number) THEN
11790 -- display Date
11791 l_document := l_document || td_text;
11792 l_document := l_document || l_start_date || td_end;
11793 -- display Expense Type
11794 l_document := l_document || td_text || l_expense_type || td_end;
11795 -- display Merchant Name
11796 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
11797 l_document := l_document || td_text || WF_NOTIFICATION.SubstituteSpecialChars(l_merchant_name) || td_end;
11798 end if;
11799
11800 if (l_employee_project_enabled = 'Y') then
11801 -- display Project/Task only when Projects enabled
11802 l_document := l_document || td_text || nvl(l_project_number, '&' || 'nbsp;') || td_end;
11803 l_document := l_document || td_text || nvl(l_task_number, '&' || 'nbsp;') || td_end;
11804 if (l_grants_enabled = 'Y') then
11805 l_document := l_document || td_text || nvl(l_award_number, '&' || 'nbsp;') || td_end;
11806 end if;
11807 end if;
11808
11809 -- display Amount
11810 l_document := l_document || td_number || LPAD(to_char(l_total_amt, FND_CURRENCY.Get_Format_Mask(l_currency,22)),14) || td_end;
11811
11812 -- display Justification
11813 l_document := l_document || td_text || nvl(WF_NOTIFICATION.SubstituteSpecialChars(l_justification), '&' || 'nbsp;') || td_end;
11814
11815 if (l_line_accounting_enabled = 'Y') then
11816 l_document := l_document || td_text || nvl(l_flex_concatenated, '&' || 'nbsp;') || td_end;
11817 end if;
11818
11819 ELSE
11820 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
11821 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
11822
11823 -- display Merchant Name
11824 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
11825 l_document := l_document || td_text || WF_NOTIFICATION.SubstituteSpecialChars(l_merchant_name) || td_end;
11826 end if;
11827
11828 if (l_employee_project_enabled = 'Y') then
11829 -- display Project/Task only when Projects enabled
11830 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
11831 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
11832 if (l_grants_enabled = 'Y') then
11833 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
11834 end if;
11835 end if;
11836
11837
11838 -- display Amount
11839 l_document := l_document || td_number || '&' || 'nbsp;'|| td_end;
11840
11841 -- display Justification
11842 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
11843
11844 if (l_line_accounting_enabled = 'Y') then
11845 l_document := l_document || td_text || '&' || 'nbsp;' || td_end;
11846 end if;
11847
11848 END IF;
11849
11850
11851
11852 l_document := l_document || tr_end;
11853
11854 IF (l_distribution_line_number <> l_last_dist_number) THEN
11855 l_expense_report_total_amt := l_expense_report_total_amt + l_total_amt;
11856 END IF;
11857
11858 END IF;
11859
11860 l_last_dist_number := l_distribution_line_number;
11861 END LOOP; -- GetDisplayXpenseLinesCursor
11862
11863 END IF; -- GetDisplayXpenseLinesCursor
11864
11865 if XpenseLinesCursor%isopen then
11866 close XpenseLinesCursor;
11867 end if;
11868
11869 --------------------------------------------
11870 l_debug_info := 'Generate Total Row';
11871 --------------------------------------------
11872 l_document := l_document || tr_start;
11873 if (l_employee_project_enabled = 'Y') then
11874 if (l_grants_enabled = 'Y') and (l_print_violation = 'Y') then
11875 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
11876 l_colspan := 9;
11877 else
11878 l_colspan := 8;
11879 end if;
11880 elsif (l_grants_enabled = 'Y') and (l_print_violation = 'N') then
11881 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
11882 l_colspan := 7;
11883 else
11884 l_colspan := 6;
11885 end if;
11886 elsif (l_grants_enabled = 'N') and (l_print_violation = 'Y') then
11887 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
11888 l_colspan := 8;
11889 else
11890 l_colspan := 7;
11891 end if;
11892 elsif (l_grants_enabled = 'N') and (l_print_violation = 'N') then
11893 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
11894 l_colspan := 6;
11895 else
11896 l_colspan := 5;
11897 end if;
11898 end if;
11899 else
11900 if (l_grants_enabled = 'Y') and (l_print_violation = 'Y') then
11901 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
11902 l_colspan := 7;
11903 else
11904 l_colspan := 6;
11905 end if;
11906 elsif (l_grants_enabled = 'Y') and (l_print_violation = 'N') then
11907 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
11908 l_colspan := 4;
11909 else
11910 l_colspan := 3;
11911 end if;
11912 elsif (l_grants_enabled = 'N') and (l_print_violation = 'Y') then
11913 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
11914 l_colspan := 6;
11915 else
11916 l_colspan := 5;
11917 end if;
11918 elsif (l_grants_enabled = 'N') and (l_print_violation = 'N') then
11919 if ((l_is_cc_table) or (NOT l_is_cc_table and l_co_merchant_count > 0)) then
11920 l_colspan := 4;
11921 else
11922 l_colspan := 3;
11923 end if;
11924 end if;
11925 end if;
11926 -- display Total
11927 l_document := l_document || '<td colspan=' || l_colspan ||
11928 ' 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}">' ||
11929 l_prompts(12) || td_end;
11930
11931 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;
11932 l_document := l_document || th_number || '&' || 'nbsp;' || td_end;
11933
11934 if (l_line_accounting_enabled = 'Y') then
11935 l_document := l_document || th_number || '&' || 'nbsp;' || td_end;
11936 end if;
11937 l_document := l_document || tr_end;
11938 l_document := l_document || table_end || indent_end;
11939
11940 end if; -- traverse selected lines
11941
11942 end loop; -- l_table_loop_counter
11943
11944
11945 --------------------------------------------
11946 l_debug_info := 'Display Company Pay Corporate Credit Card Personal Expenses';
11947 --------------------------------------------
11948
11949 --------------------------------------------
11950 l_debug_info := 'Check to see if Company Pay scenario';
11951 --------------------------------------------
11952 begin
11953 l_payment_due_from := WF_ENGINE.GetItemAttrText(l_itemtype,l_itemkey,'PAYMENT_DUE_FROM');
11954 exception
11955 when others then
11956 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
11957 null;
11958 else
11959 raise;
11960 end if;
11961 end;
11962 if (l_show_message = 'N' AND C_CompanyPay = l_payment_due_from) then
11963
11964 --------------------------------------------
11965 l_debug_info := 'get Number of Personal Credit Card lines';
11966 --------------------------------------------
11967 if (AP_WEB_DB_EXPLINE_PKG.GetNumberOfPersonalLines(l_report_header_id, l_num_personal_lines)) then null; end if;
11968
11969 if (l_num_personal_lines > 0) then
11970
11971 --------------------------------------------
11972 l_debug_info := 'Generate Table Header';
11973 --------------------------------------------
11974 l_document := l_document || indent_start || table_title_start || l_prompts(3) || table_title_end;
11975
11976 l_document := l_document || table_start;
11977
11978 l_document := l_document || tr_start;
11979 -- display Date
11980 l_document := l_document || th_text || l_prompts(4) || td_end;
11981
11982 -- display Merchant
11983 --Bug 2942773: Add Merchant Name to personal Expenses Table.
11984 l_document := l_document || th_text || l_prompts(27) || td_end;
11985 -- display Amount
11986 l_document := l_document || th_number || l_prompts(9) || td_end;
11987 l_document := l_document || tr_end;
11988
11989 --------------------------------------------
11990 l_debug_info := 'Open Personal Lines Cursor';
11991 --------------------------------------------
11992 IF (AP_WEB_DB_EXPLINE_PKG.GetDisplayPersonalLinesCursor(l_report_header_id, PersonalLinesCursor)) THEN
11993
11994 l_num_lines := 0;
11995 l_cc_personal_total_amt := 0;
11996 LOOP
11997
11998 --------------------------------------------
11999 l_debug_info := 'Fetch Personal Lines Cursor';
12000 --------------------------------------------
12001 FETCH PersonalLinesCursor INTO l_receipt_missing_flag,
12002 l_start_date,
12003 l_days,
12004 l_daily_amt,
12005 l_receipt_curr,
12006 l_receipt_rate,
12007 l_receipt_amt,
12008 l_total_amt,
12009 l_justification,
12010 l_expense_type,
12011 l_project_number,
12012 l_task_number,
12013 l_credit_card_trx_id,
12014 l_distribution_line_number,
12015 l_merchant_name; --Bug 29427743.
12016 EXIT WHEN PersonalLinesCursor%NOTFOUND;
12017
12018 IF lengthb(l_document) >= l_document_max THEN
12019 -- Appends l_document to end of document (CLOB object)
12020 WF_NOTIFICATION.WriteToClob(document,l_document);
12021 l_document := '';
12022 --l_show_message := 'Y';
12023 --exit;
12024 END IF;
12025
12026 l_total_amt := -(l_total_amt) ; -- Bug 2824304. Reversing the sign of Personal Expenses since they are negated and stored in database.
12027 l_num_lines := l_num_lines + 1;
12028
12029 -- Bug 2824304: Removed use of abs function for displaying Personal Expenses Amount and the Total.
12030
12031 l_document := l_document || tr_start;
12032
12033 -- display Date
12034 l_document := l_document || td_text || l_start_date || td_end;
12035
12036 -- display Merchant
12037 --Bug 2942773: Add Merchant name value to personal expense table.
12038 l_document := l_document || td_text || WF_NOTIFICATION.SubstituteSpecialChars(l_merchant_name) || td_end;
12039 -- display Amount
12040 l_document := l_document || td_number || LPAD(to_char(l_total_amt, FND_CURRENCY.Get_Format_Mask(l_currency,22)),14) || td_end;
12041 l_document := l_document || tr_end;
12042
12043 l_cc_personal_total_amt := l_cc_personal_total_amt + l_total_amt;
12044
12045 END LOOP; -- GetDisplayPersonalLinesCursor
12046
12047 END IF; -- GetDisplayPersonalLinesCursor
12048
12049 if PersonalLinesCursor%isopen then
12050 close PersonalLinesCursor;
12051 end if;
12052 --------------------------------------------
12053 l_debug_info := 'Generate Total Row';
12054 --------------------------------------------
12055 l_document := l_document || tr_start;
12056 --Bug 2942773: Add colspans to Total AMount so that it will appear under Amount
12057
12058 -- display Total
12059 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;
12060
12061 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;
12062 l_document := l_document || tr_end;
12063 l_document := l_document || table_end || indent_end;
12064
12065 end if; -- l_num_personal_lines > 0
12066
12067 end if; -- Display Company Pay Corporate Credit Card Personal Expenses
12068
12069 /*Bug 2944363: Added code to show the table for personal expenses in Both Pay.*/
12070
12071 --AMMISHRA - Both Pay Personal Only Lines project.
12072
12073 --------------------------------------------
12074 l_debug_info := 'Check to see if Both Pay scenario';
12075 --------------------------------------------
12076 IF (NOT AP_WEB_DB_EXPRPT_PKG.getPaymentDueFromReport(l_report_header_id,l_payment)) THEN
12077 l_debug_info := 'Could not set workflow attribute Payment_Due_From';
12078 END IF;
12079 if (l_show_message = 'N' AND C_BothPay = l_payment) then
12080 --------------------------------------------
12081 l_debug_info := 'get Number of Personal Credit Card lines Both Pay';
12082 --------------------------------------------
12083 if (AP_WEB_DB_EXPLINE_PKG.GetNoOfBothPayPersonalLines(l_report_header_id, l_num_personal_lines)) then null; end if;
12084 if (l_num_personal_lines > 0) then
12085
12086 --------------------------------------------
12087 l_debug_info := 'Generate Table Header';
12088 --------------------------------------------
12089 l_document := l_document || indent_start || table_title_start || l_prompts(3) || table_title_end;
12090
12091 l_document := l_document || table_start;
12092
12093 l_document := l_document || tr_start;
12094
12095 -- display Date
12096 l_document := l_document || th_text || l_prompts(4) || td_end;
12097
12098 -- display Merchant
12099 l_document := l_document || th_text || l_prompts(27) || td_end;
12100
12101 -- display Amount
12102 l_document := l_document || th_number || l_prompts(9) || td_end;
12103
12104 l_document := l_document || tr_end;
12105
12106 ------------------End Of Table Header------------------
12107 --------------------------------------------
12108 l_debug_info := 'Open BothPay Personal Lines Cursor';
12109 --------------------------------------------
12110 IF (AP_WEB_DB_EXPLINE_PKG.GetBothPayPersonalLinesCursor(l_report_header_id, BothPayPersonalLinesCursor)) THEN
12111
12112 l_num_lines := 0;
12113 l_cc_personal_total_amt := 0;
12114 LOOP
12115
12116 --------------------------------------------
12117 l_debug_info := 'Fetch Personal Lines Cursor';
12118 --------------------------------------------
12119 FETCH BothPayPersonalLinesCursor INTO
12120 l_cc_trxn_date,
12121 l_cc_expensed_amt,
12122 l_cc_curr_code,
12123 l_cc_merchant_name;
12124 EXIT WHEN BothPayPersonalLinesCursor%NOTFOUND;
12125 IF lengthb(l_document) >= l_document_max THEN
12126 -- Appends l_document to end of document (CLOB object)
12127 WF_NOTIFICATION.WriteToClob(document,l_document);
12128 l_document := '';
12129 --l_show_message := 'Y';
12130 --exit;
12131 END IF;
12132 l_num_lines := l_num_lines + 1;
12133
12134 l_document := l_document || tr_start;
12135 -- display Date
12136 l_document := l_document || td_text || l_cc_trxn_date || td_end;
12137 -- display Merchant
12138 l_document := l_document || td_text || WF_NOTIFICATION.SubstituteSpecialChars(l_cc_merchant_name) || td_end;
12139 -- display Amount
12140 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;
12141 l_document := l_document || tr_end;
12142
12143 l_cc_personal_total_amt := l_cc_personal_total_amt + to_number(l_cc_expensed_amt);
12144
12145 END LOOP; -- GetDisplayPersonalLinesCursor
12146
12147 END IF; -- GetDisplayPersonalLinesCursor
12148
12149 if BothPayPersonalLinesCursor%isopen then
12150 close BothPayPersonalLinesCursor;
12151 end if;
12152
12153 --------------------------------------------
12154 l_debug_info := 'Generate Total Row';
12155 --------------------------------------------
12156 l_document := l_document || tr_start;
12157 -- display Total
12158 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;
12159 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;
12160 l_document := l_document || tr_end;
12161 l_document := l_document || table_end || indent_end;
12162
12163 end if; -- l_num_personal_lines > 0
12164
12165 end if; -- Display Both Pay Corporate Credit Card Personal Expenses
12166
12167 --2944363:End of Both pay Personal Table.
12168
12169 --------------------------------------------
12170 l_debug_info := 'Unable to show more lines';
12171 --------------------------------------------
12172 IF l_show_message = 'Y' THEN
12173 FND_MESSAGE.SET_NAME('SQLAP','AP_WEB_EXP_UNABLE_TO_SHOWLINES');
12174 FND_MESSAGE.SET_TOKEN('NO_OF_LINES',to_char(l_num_lines));
12175 l_message := FND_MESSAGE.GET;
12176 l_document := l_document || table_start;
12177 l_document := l_document || tr_start || '&' || 'nbsp;' || tr_end;
12178 l_document := l_document || tr_start || '&' || 'nbsp;' || tr_end;
12179 l_document := l_document || tr_start || td_start || l_message || td_end || tr_end;
12180 l_document := l_document || table_end || indent_end;
12181 END IF;
12182
12183 end if; -- text/plain vs text/html
12184
12185 /* Bug 3561386 : Should add l_document to the clob only if it is
12186 * not null.
12187 */
12188 IF l_document is not null then
12189 WF_NOTIFICATION.WriteToClob(document,l_document);
12190 END IF;
12191
12192 document_type := display_type;
12193
12194 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateExpClobLines');
12195
12196 EXCEPTION
12197 WHEN OTHERS THEN
12198 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateExpClobLines',
12199 document_id, l_debug_info);
12200 raise;
12201 END GenerateExpClobLines;
12202
12203 -------------------------------------------------------------------------------
12204 PROCEDURE determineMileageAdjusted(p_item_type IN VARCHAR2,
12205 p_item_key IN VARCHAR2,
12206 p_actid IN NUMBER,
12207 p_funmode IN VARCHAR2,
12208 p_result OUT NOCOPY VARCHAR2) IS
12209 -------------------------------------------------------------------------------
12210 l_debug_info VARCHAR2(200);
12211 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_HeaderID;
12212 l_modified_count NUMBER :=0;
12213 l_new_count NUMBER :=0;
12214 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
12215
12216 BEGIN
12217
12218 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start determineMileageAdjusted');
12219
12220 IF (p_funmode = 'RUN') THEN
12221
12222 ------------------------------------------------------------
12223 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
12224 ------------------------------------------------------------
12225 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
12226 p_item_key,
12227 'EXPENSE_REPORT_ID');
12228
12229
12230
12231 ------------------------------------------------------------
12232 l_debug_info := 'Construct Mileage Note';
12233 ------------------------------------------------------------
12234 SELECT count(*)
12235 INTO l_modified_count
12236 FROM ap_expense_report_lines xl
12237 WHERE xl.report_header_id = l_report_header_id
12238 AND xl.mileage_rate_adjusted_flag = AP_WEB_DB_EXPLINE_PKG.C_Modified;
12239
12240 /* If the system adjusted the mileage rate by adding new lines
12241 and changing the rate in the same report, the notes on the
12242 notification will only display the modified message. Only
12243 one notification will be send to the preparer and AP. */
12244 IF (l_modified_count > 0) THEN
12245 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_MRATE_MODIFIED_NOTE');
12246 ELSE
12247 SELECT count(*)
12248 INTO l_new_count
12249 FROM ap_expense_report_lines xl
12250 WHERE xl.report_header_id = l_report_header_id
12251 AND (xl.mileage_rate_adjusted_flag = AP_WEB_DB_EXPLINE_PKG.C_New
12252 OR xl.mileage_rate_adjusted_flag = AP_WEB_DB_EXPLINE_PKG.C_Split);
12253
12254 IF (l_new_count > 0 ) THEN
12255 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_MRATE_SPLIT_NOTE');
12256 END IF;
12257 END IF;
12258
12259 l_mess := FND_MESSAGE.GET;
12260
12261 WF_ENGINE.SetItemAttrText(p_item_type,
12262 p_item_key,
12263 'MILEAGE_NOTE',
12264 l_mess);
12265
12266 IF (l_modified_count > 0 OR l_new_count > 0 ) THEN
12267 p_result := 'COMPLETE:Y';
12268 ELSE
12269 p_result := 'COMPLETE:N';
12270 END IF;
12271
12272
12273 ELSIF (p_funmode = 'CANCEL') THEN
12274 p_result := 'COMPLETE';
12275 END IF;
12276
12277 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end determineMileageAdjusted');
12278
12279 EXCEPTION
12280 WHEN OTHERS THEN
12281 AP_WEB_DB_UTIL_PKG.RaiseException('determineMileageAdjusted');
12282 APP_EXCEPTION.RAISE_EXCEPTION;
12283 END determineMileageAdjusted;
12284
12285
12286
12287 ---------------------------------------------------------
12288 PROCEDURE getScheduleLineArray(
12289 p_report_header_id IN NUMBER,
12290 p_distribution_line_number IN NUMBER,
12291 p_employee_id IN NUMBER,
12292 p_cumulative_mileage IN NUMBER,
12293 p_schedule_line_array OUT NOCOPY AP_WEB_DB_SCHLINE_PKG.Schedule_Line_Array) IS
12294 ---------------------------------------------------------
12295 l_vehicle_category_code AP_WEB_DB_EXPLINE_PKG.expLines_vehicle_category_code;
12296 l_vehicle_type AP_WEB_DB_EXPLINE_PKG.expLines_vehicle_type;
12297 l_fuel_type AP_WEB_DB_EXPLINE_PKG.expLines_fuel_type;
12298 l_trip_distance AP_WEB_DB_EXPLINE_PKG.expLines_trip_distance;
12299 l_distance_unit_code AP_WEB_DB_EXPLINE_PKG.expLines_distance_unit_code;
12300 l_currency_code AP_WEB_DB_EXPLINE_PKG.expLines_currCode;
12301 l_start_expense_date AP_WEB_DB_EXPLINE_PKG.expLines_startExpDate;
12302 l_end_expense_date AP_WEB_DB_EXPLINE_PKG.expLines_endExpDate;
12303 l_web_parameter_iD AP_WEB_DB_EXPLINE_PKG.expLines_webParamID;
12304 l_policy_id AP_EXPENSE_REPORT_PARAMS.COMPANY_POLICY_ID%TYPE;
12305 l_distance_uom AP_POL_HEADERS.DISTANCE_UOM%TYPE;
12306 l_employee_role_flag AP_POL_HEADERS.EMPLOYEE_ROLE_FLAG%TYPE;
12307 l_distance_thresholds_flag AP_POL_HEADERS.DISTANCE_THRESHOLDS_FLAG%TYPE;
12308 l_debug_info VARCHAR2(200);
12309 l_cumulative_mileage AP_WEB_EMPLOYEE_INFO.NUMERIC_VALUE%TYPE := nvl(p_cumulative_mileage,0);
12310 l_currency_preference AP_POL_HEADERS.CURRENCY_PREFERENCE%TYPE;
12311 bDistanceWithinRange BOOLEAN := FALSE;
12312 bDistanceThresholdCrossed BOOLEAN := FALSE;
12313 bFoundSingleRate BOOLEAN := FALSE;
12314 l_schedule_line_array AP_WEB_DB_SCHLINE_PKG.Schedule_Line_Array;
12315 l_orig_cum_mileage AP_WEB_EMPLOYEE_INFO.VALUE_TYPE%TYPE;
12316 i NUMBER := 1;
12317 j NUMBER := 1;
12318
12319 c_schedule_line_cursor AP_WEB_DB_SCHLINE_PKG.ScheduleLinesCursor;
12320
12321 BEGIN
12322 --------------------------------------------------
12323 l_debug_info := 'Retrieving info from the Database';
12324 --------------------------------------------------
12325
12326 SELECT XL.VEHICLE_CATEGORY_CODE,
12327 XL.VEHICLE_TYPE,
12328 XL.FUEL_TYPE,
12329 nvl(XL.TRIP_DISTANCE,0),
12330 XL.DISTANCE_UNIT_CODE,
12331 XL.CURRENCY_CODE,
12332 XL.START_EXPENSE_DATE,
12333 XL.END_EXPENSE_DATE,
12334 XL.WEB_PARAMETER_ID,
12335 XP.COMPANY_POLICY_ID,
12336 SH.CURRENCY_PREFERENCE
12337 INTO l_vehicle_category_code,
12338 l_vehicle_type,
12339 l_fuel_type,
12340 l_trip_distance,
12341 l_distance_unit_code,
12342 l_currency_code,
12343 l_start_expense_date,
12344 l_end_expense_date,
12345 l_web_parameter_id,
12346 l_policy_id,
12347 l_currency_preference
12348 FROM ap_expense_report_lines XL,
12349 AP_EXPENSE_REPORT_HEADERS XH,
12350 AP_EXPENSE_REPORT_PARAMS XP,
12351 AP_POL_HEADERS SH
12352 WHERE XH.report_header_id = p_report_header_id
12353 AND XH.report_header_id = XL.report_header_id
12354 AND XL.distribution_line_number = p_distribution_line_number
12355 AND (XP.WEB_ENABLED_FLAG = 'Y'
12356 OR XH.EXPENSE_REPORT_ID = XP.EXPENSE_REPORT_ID)
12357 AND XL.web_parameter_id = XP.parameter_id
12358 AND XP.company_policy_id = SH.policy_id;
12359
12360 --------------------------------------------------
12361 l_debug_info := 'Retrieving info from the ap_pol_headers';
12362 --------------------------------------------------
12363 SELECT AH.DISTANCE_UOM,
12364 AH.DISTANCE_THRESHOLDS_FLAG,
12365 AH.EMPLOYEE_ROLE_FLAG
12366 INTO l_distance_uom,
12367 l_distance_thresholds_flag,
12368 l_employee_role_flag
12369 FROM AP_POL_HEADERS AH
12370 WHERE AH.POLICY_ID = l_policy_id;
12371
12372 IF (l_distance_thresholds_flag is not null) THEN
12373 IF ((l_distance_uom = C_KILOMETERS) AND (l_distance_unit_code = C_MILES)) THEN
12374 if l_distance_unit_code = C_MILES then
12375 l_trip_distance := l_trip_distance * MILES_TO_KILOMETERS;
12376 ELSIF ((l_distance_uom = C_MILES) AND (l_distance_unit_code = C_KILOMETERS)) THEN
12377 l_cumulative_mileage := round((l_cumulative_mileage * KILOMETERS_TO_MILES),1);
12378 l_trip_distance := l_trip_distance * KILOMETERS_TO_MILES;
12379 ELSIF ((l_distance_uom = C_SWMILES) AND (l_distance_unit_code = C_KILOMETERS)) THEN
12380 l_cumulative_mileage := round((l_cumulative_mileage * KILOMETERS_TO_SWMILES),1);
12381 l_trip_distance := l_trip_distance * KILOMETERS_TO_SWMILES;
12382 ELSIF ((l_distance_uom = C_SWMILES) AND (l_distance_unit_code = C_MILES)) THEN
12383 l_cumulative_mileage := round((l_cumulative_mileage * MILES_TO_SWMILES),1);
12384 l_trip_distance := l_trip_distance * MILES_TO_SWMILES;
12385 ELSIF ((l_distance_uom = C_KILOMETERS) AND (l_distance_unit_code = C_SWMILES)) then
12386 l_trip_distance := l_trip_distance * SWMILES_TO_KILOMETERS;
12387 ELSIF ((l_distance_uom = C_MILES) AND (l_distance_unit_code = C_SWMILES)) THEN
12388 l_cumulative_mileage := round((l_cumulative_mileage * SWMILES_TO_MILES),1);
12389 l_trip_distance := l_trip_distance * SWMILES_TO_MILES;
12390 ELSIF ((l_distance_uom = C_MILES) AND (l_distance_unit_code = C_MILES)) THEN
12391 l_cumulative_mileage := round((l_cumulative_mileage * KILOMETERS_TO_MILES),1);
12392 ELSIF ((l_distance_uom = C_SWMILES) AND (l_distance_unit_code = C_SWMILES)) THEN
12393 l_cumulative_mileage := round((l_cumulative_mileage * KILOMETERS_TO_SWMILES),1);
12394 END IF;
12395 END IF;
12396 END IF;
12397
12398
12399 --------------------------------------------------
12400 l_debug_info := 'Retrieving schedule line from the ap_pol_lines';
12401 --------------------------------------------------
12402 l_orig_cum_mileage := l_cumulative_mileage;
12403 l_cumulative_mileage := l_cumulative_mileage + l_trip_distance;
12404
12405 IF ( AP_WEB_DB_SCHLINE_PKG.GetScheduleLinesCursor(l_policy_id,
12406 l_vehicle_category_code,
12407 l_vehicle_type,
12408 l_fuel_type,
12409 l_currency_code,
12410 p_employee_id,
12411 l_start_expense_date,
12412 c_schedule_line_cursor)) THEN
12413
12414 LOOP
12415 FETCH c_schedule_line_cursor INTO
12416 l_schedule_line_array(i).range_high,
12417 l_schedule_line_array(i).range_low,
12418 l_schedule_line_array(i).start_date,
12419 l_schedule_line_array(i).end_date,
12420 l_schedule_line_array(i).rate,
12421 l_schedule_line_array(i).rate_per_passenger;
12422 EXIT WHEN c_schedule_line_cursor%NOTFOUND;
12423
12424 --------------------------------------------------
12425 l_debug_info := 'Determine whether distance threshold crossed';
12426 --------------------------------------------------
12427 IF (l_distance_thresholds_flag is not null) THEN
12428 IF (l_orig_cum_mileage <
12429 nvl(l_schedule_line_array(i).range_high,l_orig_cum_mileage + 1)) THEN
12430 IF (l_cumulative_mileage > nvl(l_schedule_line_array(i).range_high + C_THRESHOLD_TOLERANCE, l_cumulative_mileage)) THEN
12431 bDistanceThresholdCrossed := TRUE;
12432 ELSE
12433 bDistanceThresholdCrossed := FALSE;
12434 END IF;
12435
12436 p_schedule_line_array(j) := l_schedule_line_array(i);
12437 IF (bDistanceThresholdCrossed = FALSE) THEN
12438 EXIT;
12439 END IF;
12440
12441 j := j+1;
12442 END IF;
12443 END IF;
12444
12445
12446 i := i+1;
12447 END LOOP;
12448
12449 END IF;
12450
12451 EXCEPTION
12452 WHEN OTHERS THEN
12453 AP_WEB_DB_UTIL_PKG.RaiseException('getScheduleLineArray',
12454 l_debug_info);
12455 APP_EXCEPTION.RAISE_EXCEPTION;
12456 END getScheduleLineArray;
12457
12458
12459 -------------------------------------------------------------------------------
12460 PROCEDURE updateCumulativeMileage(
12461 p_cumulative_mileage IN AP_WEB_EMPLOYEE_INFO.NUMERIC_VALUE%TYPE,
12462 p_period_id IN AP_WEB_EMPLOYEE_INFO.PERIOD_ID%TYPE,
12463 p_employee_id IN AP_WEB_EMPLOYEE_INFO.EMPLOYEE_ID%TYPE) IS
12464 -------------------------------------------------------------------------------
12465 l_count NUMBER := 0;
12466 BEGIN
12467
12468 SELECT count(*)
12469 INTO l_count
12470 FROM ap_web_employee_info_all
12471 WHERE value_type = 'CUM_REIMB_DISTANCE'
12472 AND period_id = p_period_id
12473 AND employee_id = p_employee_id;
12474
12475 IF (l_count > 0 ) THEN
12476 UPDATE ap_web_employee_info_all
12477 SET numeric_value = p_cumulative_mileage,
12478 last_update_date = sysdate,
12479 last_updated_by = p_employee_id
12480 WHERE value_type = 'CUM_REIMB_DISTANCE'
12481 AND period_id = p_period_id
12482 AND employee_id = p_employee_id;
12483 ELSE
12484 INSERT INTO ap_web_employee_info_all
12485 (EMPLOYEE_ID,
12486 VALUE_TYPE,
12487 NUMERIC_VALUE,
12488 PERIOD_ID,
12489 CREATION_DATE,
12490 CREATED_BY,
12491 LAST_UPDATE_DATE,
12492 LAST_UPDATED_BY,
12493 ORG_ID)
12494 VALUES(p_employee_id,
12495 'CUM_REIMB_DISTANCE',
12496 p_cumulative_mileage,
12497 p_period_id,
12498 sysdate,
12499 p_employee_id,
12500 sysdate,
12501 p_employee_id,
12502 mo_global.get_current_org_id() );
12503 END IF;
12504
12505 EXCEPTION
12506 WHEN OTHERS THEN
12507 AP_WEB_DB_UTIL_PKG.RaiseException('updateCumulativeMileage');
12508 APP_EXCEPTION.RAISE_EXCEPTION;
12509 END updateCumulativeMileage;
12510
12511
12512 FUNCTION getAddonMileageRatesSum(p_report_header_id IN NUMBER,
12513 p_dist_line_number IN NUMBER)
12514 RETURN NUMBER IS
12515 l_addon_rate_sum NUMBER := 0.0;
12516 BEGIN
12517 -- Bug: 7330731, Null returned from here causes invalid splits
12518 select nvl(sum(mileage_rate),0)
12519 into l_addon_rate_sum
12520 from oie_addon_mileage_rates
12521 where report_line_id = (select report_line_id
12522 from ap_expense_report_lines
12523 where report_header_id = p_report_header_id
12524 and distribution_line_number = p_dist_line_number
12525 and rownum = 1);
12526 return l_addon_rate_sum;
12527 EXCEPTION when others then
12528 return l_addon_rate_sum;
12529 END getAddonMileageRatesSum;
12530
12531 -------------------------------------------------------------------------------
12532 FUNCTION getRate(
12533 p_sh_distance_uom IN AP_POL_HEADERS.distance_uom%TYPE,
12534 p_sh_currency_code IN AP_POL_HEADERS.currency_code%TYPE,
12535 p_mileage_line IN AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Rec,
12536 p_schedule_line IN AP_WEB_DB_SCHLINE_PKG.Schedule_Line_Rec)
12537 RETURN NUMBER IS
12538 -------------------------------------------------------------------------------
12539 l_debug_info VARCHAR2(200);
12540 l_conversion_type VARCHAR2(30);
12541 l_converted_amount NUMBER := 1;
12542 l_denominator NUMBER := 1;
12543 l_numerator NUMBER := 1;
12544 l_rate NUMBER;
12545
12546 l_get_ap_system_params boolean;
12547 l_base_curr_code AP_WEB_DB_AP_INT_PKG.apSetup_baseCurrencyCode;
12548 l_set_of_books_id AP_WEB_DB_AP_INT_PKG.apSetup_setOfBooksID;
12549 l_expense_report_id AP_WEB_DB_AP_INT_PKG.apSetup_expenseReportID;
12550
12551 BEGIN
12552
12553 -- Need to convert to reimbursement currency if different
12554 IF (p_sh_currency_code <> p_mileage_line.reimbursement_currency_code) THEN
12555
12556 ------------------------------------------------------
12557 l_debug_info := 'Get the rate type';
12558 ------------------------------------------------------
12559 l_get_ap_system_params := AP_WEB_DB_AP_INT_PKG.get_ap_system_params(
12560 p_base_curr_code => l_base_curr_code,
12561 p_set_of_books_id => l_set_of_books_id,
12562 p_expense_report_id => l_expense_report_id,
12563 p_default_exch_rate_type => l_conversion_type);
12564
12565
12566
12567 gl_currency_api.convert_closest_amount(
12568 x_from_currency => p_sh_currency_code,
12569 x_to_currency => p_mileage_line.reimbursement_currency_code,
12570 x_conversion_date => p_mileage_line.start_date,
12571 x_conversion_type => l_conversion_type,
12572 x_user_rate => 1,
12573 x_amount => 1,
12574 x_max_roll_days => 0,
12575 x_converted_amount=> l_converted_amount,
12576 x_denominator => l_denominator,
12577 x_numerator => l_numerator,
12578 x_rate => l_rate);
12579 l_rate := p_schedule_line.rate * l_rate;
12580 ELSE
12581 l_rate := p_schedule_line.rate;
12582 END IF;
12583
12584 ------------------------------------------------------
12585 l_debug_info := 'Convert rate to the corresponding UOM';
12586 ------------------------------------------------------
12587 IF (p_sh_distance_uom <> p_mileage_line.distance_unit_code) THEN
12588
12589 IF ((p_sh_distance_uom = C_KILOMETERS) AND (p_mileage_line.distance_unit_code = C_MILES)) THEN
12590 l_rate := round( p_schedule_line.rate * MILES_TO_KILOMETERS, 6);
12591 ELSIF ((p_sh_distance_uom = C_MILES) AND (p_mileage_line.distance_unit_code = C_KILOMETERS)) THEN
12592 l_rate := round( p_schedule_line.rate * KILOMETERS_TO_MILES, 6);
12593 ELSIF ((p_sh_distance_uom = C_SWMILES) AND (p_mileage_line.distance_unit_code = C_KILOMETERS)) THEN
12594 l_rate := round( p_schedule_line.rate * KILOMETERS_TO_SWMILES, 6);
12595 ELSIF ((p_sh_distance_uom = C_SWMILES) AND (p_mileage_line.distance_unit_code = C_MILES)) THEN
12596 l_rate := round( p_schedule_line.rate * MILES_TO_SWMILES, 6);
12597 ELSIF ((p_sh_distance_uom = C_MILES) AND (p_mileage_line.distance_unit_code = C_SWMILES)) THEN
12598 l_rate := round( p_schedule_line.rate * SWMILES_TO_MILES, 6);
12599 ELSIF ((p_sh_distance_uom = C_KILOMETERS) AND (p_mileage_line.distance_unit_code = C_SWMILES)) THEN
12600 l_rate := round( p_schedule_line.rate * SWMILES_TO_KILOMETERS, 6);
12601
12602 END IF;
12603
12604 END IF;
12605
12606 return l_rate;
12607
12608 EXCEPTION
12609 WHEN NO_DATA_FOUND THEN
12610 return 0;
12611 WHEN OTHERS THEN
12612 AP_WEB_DB_UTIL_PKG.RaiseException('getRate');
12613 APP_EXCEPTION.RAISE_EXCEPTION;
12614 return 0;
12615 END getRate;
12616
12617
12618 -------------------------------------------------------------------------------
12619 PROCEDURE copyMileageArray(
12620 p_from_array IN AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array,
12621 p_to_array OUT NOCOPY AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array) IS
12622 -------------------------------------------------------------------------------
12623 l_debug_info VARCHAR2(200);
12624
12625 BEGIN
12626 -- Start w/ defaulting the orig_dist_line_number to new_orig_dist_line_number
12627 FOR i IN 1..p_from_array.COUNT LOOP
12628 p_to_array(i).orig_dist_line_number := p_from_array(i).orig_dist_line_number;
12629 p_to_array(i).new_dist_line_number := p_from_array(i).orig_dist_line_number;
12630 p_to_array(i).report_header_id := p_from_array(i).report_header_id;
12631 p_to_array(i).start_date := p_from_array(i).start_date;
12632 p_to_array(i).end_date := p_from_array(i).end_date;
12633 p_to_array(i).number_of_days := p_from_array(i).number_of_days;
12634 p_to_array(i).policy_id := p_from_array(i).policy_id;
12635 p_to_array(i).avg_mileage_rate := p_from_array(i).avg_mileage_rate;
12636 p_to_array(i).trip_distance := p_from_array(i).trip_distance;
12637 p_to_array(i).daily_distance := p_from_array(i).daily_distance;
12638 p_to_array(i).distance_unit_code := p_from_array(i).distance_unit_code;
12639 p_to_array(i).amount := p_from_array(i).amount;
12640
12641 END LOOP;
12642
12643
12644 EXCEPTION
12645 WHEN OTHERS THEN
12646 AP_WEB_DB_UTIL_PKG.RaiseException('copyMileageArray');
12647 APP_EXCEPTION.RAISE_EXCEPTION;
12648 END copyMileageArray;
12649
12650
12651 -------------------------------------------------------------------------------
12652 PROCEDURE addToMileageArray(
12653 p_index IN NUMBER,
12654 p_new_dist_number IN AP_EXPENSE_REPORT_LINES.distribution_line_number%TYPE,
12655 p_trip_dist IN AP_EXPENSE_REPORT_LINES.TRIP_DISTANCE%TYPE,
12656 p_daily_distance IN AP_EXPENSE_REPORT_LINES.DAILY_DISTANCE%TYPE,
12657 p_rate IN AP_EXPENSE_REPORT_LINES.avg_mileage_rate%TYPE,
12658 p_report_header_id IN AP_EXPENSE_REPORT_LINES.report_header_id%TYPE,
12659 p_from_index IN AP_EXPENSE_REPORT_LINES.distribution_line_number%TYPE,
12660 p_mileage_line_array IN OUT NOCOPY AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array) IS
12661 -------------------------------------------------------------------------------
12662 l_debug_info VARCHAR2(200);
12663
12664 BEGIN
12665
12666 p_mileage_line_array(p_index).orig_dist_line_number := p_new_dist_number;
12667 p_mileage_line_array(p_index).new_dist_line_number := p_new_dist_number;
12668 p_mileage_line_array(p_index).report_header_id := p_report_header_id;
12669 p_mileage_line_array(p_index).start_date := p_mileage_line_array(p_from_index).start_date;
12670 p_mileage_line_array(p_index).end_date := p_mileage_line_array(p_from_index).end_date;
12671 p_mileage_line_array(p_index).number_of_days := p_mileage_line_array(p_from_index).number_of_days;
12672 p_mileage_line_array(p_index).policy_id := p_mileage_line_array(p_from_index).policy_id;
12673 p_mileage_line_array(p_index).avg_mileage_rate := p_rate;
12674 p_mileage_line_array(p_index).trip_distance := p_trip_dist;
12675 p_mileage_line_array(p_index).daily_distance := p_daily_distance;
12676 p_mileage_line_array(p_index).distance_unit_code := p_mileage_line_array(p_from_index).distance_unit_code;
12677 p_mileage_line_array(p_index).amount := p_rate * p_trip_dist;
12678 p_mileage_line_array(p_index).daily_amount := p_rate * p_trip_dist / p_mileage_line_array(p_from_index).number_of_days;
12679 p_mileage_line_array(p_index).copy_From := p_mileage_line_array(p_from_index).orig_dist_line_number;
12680 p_mileage_line_array(p_index).status := AP_WEB_DB_EXPLINE_PKG.C_New;
12681
12682 EXCEPTION
12683 WHEN OTHERS THEN
12684 AP_WEB_DB_UTIL_PKG.RaiseException('addToMileageArray');
12685 APP_EXCEPTION.RAISE_EXCEPTION;
12686 END addToMileageArray;
12687
12688 -------------------------------------------------------------------------------
12689 PROCEDURE updateNewDistNumber(
12690 p_index IN NUMBER,
12691 p_last_index IN NUMBER,
12692 p_added_total IN NUMBER,
12693 p_mileage_line_array IN OUT NOCOPY AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array)IS
12694 -------------------------------------------------------------------------------
12695 l_debug_info VARCHAR2(200);
12696 i NUMBER;
12697 BEGIN
12698
12699 If (p_last_index > p_index) THEN
12700 FOR i IN p_index..p_last_index LOOP
12701 p_mileage_line_array(i).new_dist_line_number :=
12702 p_mileage_line_array(i).new_dist_line_number + p_added_total;
12703
12704 -- Only the status of existing lines will be updated to M(odifed)
12705 -- All new lines will keep the N(ew) status to ensure they will
12706 -- be added to the database later.
12707
12708 IF (p_mileage_line_array(i).status <> 'N') THEN
12709 p_mileage_line_array(i).status := 'M';
12710 END IF;
12711 END LOOP;
12712
12713 END IF;
12714
12715 EXCEPTION
12716 WHEN OTHERS THEN
12717 AP_WEB_DB_UTIL_PKG.RaiseException('updateNewDistNumber');
12718 APP_EXCEPTION.RAISE_EXCEPTION;
12719 END updateNewDistNumber;
12720
12721 --------------------------------------------------------------------------------
12722 PROCEDURE processCrossThreshold(
12723 p_ml_index IN NUMBER,
12724 p_sh_distance_uom IN AP_POL_HEADERS.DISTANCE_UOM%TYPE,
12725 p_sh_currency_code IN AP_POL_HEADERS.CURRENCY_CODE%TYPE,
12726 p_schedule_line_array IN AP_WEB_DB_SCHLINE_PKG.Schedule_Line_Array,
12727 p_mileage_line_array_count IN OUT NOCOPY NUMBER,
12728 p_cumulative_mileage IN OUT NOCOPY AP_WEB_EMPLOYEE_INFO.NUMERIC_VALUE%TYPE,
12729 p_mileage_line_array IN OUT NOCOPY AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array)IS
12730 --------------------------------------------------------------------------------
12731 l_cumulative_mileage NUMBER := p_cumulative_mileage;
12732 l_ml_trip_distance NUMBER := p_mileage_line_array(p_ml_index).trip_distance;
12733 l_over_amount NUMBER;
12734 l_cum_distance NUMBER;
12735 l_over_threshold_distance NUMBER := 0;
12736 l_range_high NUMBER;
12737 l_range_low NUMBER;
12738 l_next_dist_number NUMBER;
12739 l_range_size NUMBER;
12740 l_daily_distance NUMBER;
12741 l_updated_trip_dist NUMBER;
12742 l_new_rate NUMBER := 0;
12743 l_insert_index NUMBER := p_mileage_line_array_count + 1;
12744 l_added_total NUMBER := 0;
12745 l_sl_array_count NUMBER := 0;
12746 l_debug_info VARCHAR2(200);
12747
12748
12749 BEGIN
12750
12751 ------------------------------------------------------
12752 l_debug_info := 'Convert to the appropriate UOM';
12753 ------------------------------------------------------
12754
12755 IF (p_mileage_line_array(p_ml_index).distance_unit_code = C_MILES) THEN
12756 l_cum_distance := round(((l_cumulative_mileage * KILOMETERS_TO_MILES) + p_mileage_line_array(p_ml_index).trip_distance), 1);
12757 ELSIF (p_mileage_line_array(p_ml_index).distance_unit_code = C_SWMILES) THEN
12758 l_cum_distance := round(((l_cumulative_mileage * KILOMETERS_TO_SWMILES) + p_mileage_line_array(p_ml_index).trip_distance), 1);
12759 ELSE
12760 l_cum_distance := l_cumulative_mileage + p_mileage_line_array(p_ml_index).trip_distance;
12761 END IF;
12762
12763 l_sl_array_count := p_schedule_line_array.COUNT;
12764
12765 FOR i IN 1..l_sl_array_count LOOP
12766 l_range_high := p_schedule_line_array(i).range_high;
12767 l_range_low := p_schedule_line_array(i).range_low;
12768
12769 IF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_MILES) AND (p_sh_distance_uom = C_KILOMETERS)) THEN
12770 l_range_high := p_schedule_line_array(i).range_high * KILOMETERS_TO_MILES;
12771 l_range_low := p_schedule_line_array(i).range_low * KILOMETERS_TO_MILES;
12772 ELSIF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_KILOMETERS) AND (p_sh_distance_uom = C_MILES)) THEN
12773 l_range_high := p_schedule_line_array(i).range_high * MILES_TO_KILOMETERS;
12774 l_range_low := p_schedule_line_array(i).range_low * MILES_TO_KILOMETERS;
12775 ELSIF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_KILOMETERS) AND (p_sh_distance_uom = C_SWMILES)) THEN
12776 l_range_high := p_schedule_line_array(i).range_high * SWMILES_TO_KILOMETERS;
12777 l_range_low := p_schedule_line_array(i).range_low * SWMILES_TO_KILOMETERS;
12778 ELSIF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_MILES) AND (p_sh_distance_uom = C_SWMILES)) THEN
12779 l_range_high := p_schedule_line_array(i).range_high * SWMILES_TO_MILES;
12780 l_range_low := p_schedule_line_array(i).range_low * SWMILES_TO_MILES;
12781 ELSIF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_SWMILES) AND (p_sh_distance_uom = C_MILES)) THEN
12782 l_range_high := p_schedule_line_array(i).range_high * MILES_TO_SWMILES;
12783 l_range_low := p_schedule_line_array(i).range_low * MILES_TO_SWMILES;
12784 ELSIF ((p_mileage_line_array(p_ml_index).distance_unit_code = C_SWMILES) AND (p_sh_distance_uom = C_KILOMETERS)) THEN
12785 l_range_high := p_schedule_line_array(i).range_high * KILOMETERS_TO_SWMILES;
12786 l_range_low := p_schedule_line_array(i).range_low * KILOMETERS_TO_SWMILES;
12787 END IF;
12788
12789 IF (i = 1) THEN
12790 -------------------------------------------
12791 l_debug_info := 'is distance within range';
12792 -------------------------------------------
12793 l_over_threshold_distance := l_cum_distance - nvl(l_range_high, l_cum_distance);
12794
12795 --Bug 5844609
12796 --Line shouldn't be split if over threshold distance is greater than or equal to trip distance.
12797
12798 IF (round(p_mileage_line_array(p_ml_index).trip_distance - l_over_threshold_distance)) <= 0 THEN
12799
12800 RETURN;
12801
12802 END IF;
12803
12804 IF (l_over_threshold_distance > C_THRESHOLD_TOLERANCE) THEN
12805
12806 IF (round(p_mileage_line_array(p_ml_index).trip_distance -
12807 l_over_threshold_distance)) > 0 THEN
12808
12809 p_mileage_line_array(p_ml_index).trip_distance :=
12810 (round(p_mileage_line_array(p_ml_index).trip_distance -
12811 l_over_threshold_distance));
12812 END IF;
12813
12814 p_mileage_line_array(p_ml_index).daily_distance :=
12815 round(p_mileage_line_array(p_ml_index).trip_distance /
12816 p_mileage_line_array(p_ml_index).number_of_days);
12817
12818 ELSE
12819
12820 p_mileage_line_array(p_ml_index).daily_distance :=
12821 round(p_mileage_line_array(p_ml_index).trip_distance /
12822 p_mileage_line_array(p_ml_index).number_of_days);
12823
12824 END IF;
12825 -------------------------------------------
12826 l_debug_info := 'Modify the original line';
12827 -------------------------------------------
12828 l_new_rate := getRate(
12829 p_sh_distance_uom => p_sh_distance_uom,
12830 p_sh_currency_code => p_sh_currency_code,
12831 p_mileage_line => p_mileage_line_array(p_ml_index),
12832 p_schedule_line => p_schedule_line_array(1));
12833
12834 /* Bug 3975334 : Rate per passenger logic needs to be added.
12835 rate_per_passenger will be 0 if the schedule
12836 does not have passengers_flag as 'Y'.
12837 */
12838
12839 l_new_rate := l_new_rate + nvl((p_schedule_line_array(1).rate_per_passenger *
12840 p_mileage_line_array(p_ml_index).number_people),0)+
12841 getAddonMileageRatesSum(p_mileage_line_array(p_ml_index).report_header_id,
12842 p_mileage_line_array(p_ml_index).orig_dist_line_number );
12843
12844 p_mileage_line_array(p_ml_index).avg_mileage_rate := l_new_rate;
12845 p_mileage_line_array(p_ml_index).amount :=
12846 l_new_rate * p_mileage_line_array(p_ml_index).trip_distance;
12847 p_mileage_line_array(p_ml_index).receipt_currency_amount :=
12848 p_mileage_line_array(p_ml_index).amount;
12849 p_mileage_line_array(p_ml_index).daily_amount :=
12850 l_new_rate * p_mileage_line_array(p_ml_index).trip_distance / p_mileage_line_array(p_ml_index).number_of_days;
12851 p_mileage_line_array(p_ml_index).new_dist_line_number :=
12852 p_mileage_line_array(p_ml_index).orig_dist_line_number;
12853 p_mileage_line_array(p_ml_index).status := AP_WEB_DB_EXPLINE_PKG.C_Split;
12854
12855 l_over_threshold_distance := l_cum_distance - nvl(l_range_high, l_cum_distance);
12856
12857 ELSE
12858
12859 /* When a threshold is crossed, the original line will be modified. At
12860 the same time, the system will add new lines to the lines table.
12861 The first row of the scheduleLineArray is used to modified the
12862 original line. We will need to loop through the rest of the array
12863 to decide how many new rows will be added. */
12864
12865 IF (l_over_threshold_distance > C_THRESHOLD_TOLERANCE ) THEN
12866
12867 --------------------------------------------
12868 l_debug_info := 'Creat a new receipt line';
12869 --------------------------------------------
12870
12871 SELECT max(distribution_line_number) + 1
12872 INTO l_next_dist_number
12873 FROM AP_EXPENSE_REPORT_LINES
12874 WHERE report_header_id = p_mileage_line_array(p_ml_index).report_header_id;
12875
12876 --------------------------------------------
12877 l_debug_info := 'Find the trip distance';
12878 --------------------------------------------
12879 IF (l_over_threshold_distance >= l_range_high - l_range_low) THEN
12880 l_updated_trip_dist := l_range_high - l_range_low;
12881 else
12882 l_updated_trip_dist := l_over_threshold_distance;
12883 end if;
12884
12885 l_daily_distance := l_updated_trip_dist / p_mileage_line_array(p_ml_index).number_of_days;
12886
12887 /* The rate from the schedule line array is the rate stored in
12888 ap_pol_headers. The unit of measure will be according to
12889 ap_pol_headers. However, when calculating the rate for the
12890 lines, we need to get convert the rate according to the UOM
12891 in ap_expense_report_lines. -Akita */
12892 l_new_rate := getRate(
12893 p_sh_distance_uom => p_sh_distance_uom,
12894 p_sh_currency_code => p_sh_currency_code,
12895 p_mileage_line => p_mileage_line_array(p_ml_index),
12896 p_schedule_line => p_schedule_line_array(i));
12897
12898 /* Bug 3975334 : Rate per passenger logic needs to be added.
12899 rate_per_passenger will be 0 if the schedule
12900 does not have passengers_flag as 'Y'.
12901 */
12902
12903 l_new_rate := l_new_rate + nvl((p_schedule_line_array(i).rate_per_passenger *
12904 p_mileage_line_array(p_ml_index).number_people),0)+
12905 getAddonMileageRatesSum(p_mileage_line_array(p_ml_index).report_header_id,
12906 p_mileage_line_array(p_ml_index).orig_dist_line_number );
12907 addToMileageArray(l_insert_index,
12908 l_next_dist_number,
12909 round(l_updated_trip_dist),
12910 round(l_daily_distance),
12911 l_new_rate,
12912 p_mileage_line_array(p_ml_index).report_header_id,
12913 p_ml_index,
12914 p_mileage_line_array);
12915
12916 p_mileage_line_array_count := l_insert_index ;
12917
12918 l_added_total := l_added_total + 1;
12919
12920 l_over_threshold_distance := l_cum_distance - nvl(l_range_high, l_cum_distance);
12921 END IF; -- l_over_threshold_distance > 0
12922
12923 END IF; -- i = 1
12924
12925 --------------------------------------------
12926 l_debug_info := 'assign p_cumulative_mileage';
12927 --------------------------------------------
12928 IF (p_mileage_line_array(p_ml_index).distance_unit_code = C_MILES) THEN
12929 p_cumulative_mileage := l_cum_distance * MILES_TO_KILOMETERS;
12930 ELSIF (p_mileage_line_array(p_ml_index).distance_unit_code = C_SWMILES) THEN
12931 p_cumulative_mileage := l_cum_distance * SWMILES_TO_KILOMETERS;
12932 ELSE
12933 p_cumulative_mileage := l_cum_distance;
12934 END IF;
12935
12936 END LOOP;
12937
12938 --------------------------------------------
12939 l_debug_info := 'Reorder l_mileage_array';
12940 --------------------------------------------
12941 /* Using the original count of the array to ensure the new distribution
12942 number assigned to the new rows will not be modified again in
12943 updateNewDistNumber. -Akita */
12944 updateNewDistNumber(p_ml_index + 1,
12945 l_sl_array_count,
12946 l_added_total,
12947 p_mileage_line_array);
12948
12949
12950 EXCEPTION
12951 WHEN NO_DATA_FOUND THEN
12952 AP_WEB_DB_UTIL_PKG.RaiseException('No Data found: processCrossThreshold');
12953 APP_EXCEPTION.RAISE_EXCEPTION;
12954 WHEN OTHERS THEN
12955 AP_WEB_DB_UTIL_PKG.RaiseException('processCrossThreshold');
12956 APP_EXCEPTION.RAISE_EXCEPTION;
12957 END processCrossThreshold;
12958
12959 -------------------------------------------------------------------------------
12960 PROCEDURE ProcessMileageLines(p_item_type IN VARCHAR2,
12961 p_item_key IN VARCHAR2,
12962 p_actid IN NUMBER,
12963 p_funmode IN VARCHAR2,
12964 p_result OUT NOCOPY VARCHAR2) IS
12965 -------------------------------------------------------------------------------
12966 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
12967 l_ml_start_date DATE;
12968 l_ml_end_date DATE;
12969 l_ml_numberOfDays NUMBER;
12970 l_ml_distribution_line_number AP_WEB_DB_EXPLINE_PKG.expLines_distLineNum;
12971 l_ml_policy_id AP_POL_HEADERS.policy_id%TYPE;
12972 l_cumulative_mileage AP_WEB_EMPLOYEE_INFO.NUMERIC_VALUE%TYPE;
12973 l_period_id AP_WEB_EMPLOYEE_INFO.PERIOD_ID%TYPE;
12974 l_debug_info VARCHAR2(200);
12975 C_WF_VERSION NUMBER := 0;
12976 l_new_rate NUMBER := 0;
12977 l_ml_avg_mileage_rate AP_WEB_DB_EXPLINE_PKG.expLines_avg_mileage_rate;
12978 l_ml_distance_unit_code AP_WEB_DB_EXPLINE_PKG.expLines_distance_unit_code;
12979 l_ml_trip_distance AP_WEB_DB_EXPLINE_PKG.expLines_trip_distance;
12980 c_expense_lines_cursor AP_WEB_DB_EXPLINE_PKG.ExpLinesCursor;
12981 l_employee_id NUMBER;
12982 l_schedule_line_array AP_WEB_DB_SCHLINE_PKG.Schedule_Line_Array;
12983 l_temp NUMBER;
12984 l_sh_distance_uom AP_POL_HEADERS.distance_uom%TYPE;
12985 l_sh_currency_code AP_POL_HEADERS.currency_code%TYPE;
12986 l_index NUMBER := 0;
12987 l_lines_created NUMBER := 0;
12988 l_temp_mileage_line_array AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array;
12989 l_mileage_line_array AP_WEB_DB_EXPLINE_PKG.Mileage_Line_Array;
12990 l_mileage_array_count NUMBER;
12991 i NUMBER;
12992 j NUMBER := 1;
12993 l_orig_distance_travel NUMBER;
12994 l_rate NUMBER;
12995
12996 l_base_precision NUMBER;
12997 l_ext_precision NUMBER;
12998 l_base_min_acct_unit NUMBER;
12999 l_total NUMBER;
13000 l_total_dsp VARCHAR2(50);
13001 l_bHeaderUpdated BOOLEAN := FALSE;
13002 l_reimb_curr AP_WEB_DB_EXPRPT_PKG.expHdr_payemntCurrCode;
13003 l_over_threshold_distance NUMBER := 0;
13004 l_sh_distance_thresholds_flag VARCHAR2(1);
13005
13006 l_report_header_info AP_WEB_DFLEX_PKG.ExpReportHeaderRec;
13007 l_custom_array AP_WEB_DFLEX_PKG.CustomFields_A;
13008 l_mileage_line AP_WEB_DFLEX_PKG.ExpReportLineRec;
13009 l_addon_rates OIE_ADDON_RATES_T;
13010 Custom1_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13011 Custom2_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13012 Custom3_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13013 Custom4_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13014 Custom5_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13015 Custom6_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13016 Custom7_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13017 Custom8_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13018 Custom9_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13019 Custom10_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13020 Custom11_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13021 Custom12_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13022 Custom13_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13023 Custom14_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13024 Custom15_Array AP_WEB_DFLEX_PKG.CustomFields_A;
13025 k number;
13026 cursor getAddonRates(l_report_line_id NUMBER) is select addon_rate_type
13027 from oie_addon_mileage_rates
13028 where report_line_id = l_report_line_id;
13029 l_client_extension_enabled VARCHAR2(1);
13030 l_temp_array OIE_PDM_NUMBER_T; -- bug 5358186
13031 BEGIN
13032
13033 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ProcessMileageLines');
13034
13035 -----------------------------------------------------
13036 l_debug_info := 'Get Workflow Version Number 5';
13037 -----------------------------------------------------
13038 C_WF_Version := AP_WEB_EXPENSE_WF.GetFlowVersion(p_item_type, p_item_key);
13039
13040 ------------------------------------------------------------
13041 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
13042 ------------------------------------------------------------
13043 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
13044 p_item_key,
13045 'EXPENSE_REPORT_ID');
13046 -------------------------------------------------------
13047 l_debug_info := 'Retrieve Employee_ID Item Attribute';
13048 -------------------------------------------------------
13049 l_employee_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
13050 p_item_key,
13051 'EMPLOYEE_ID');
13052
13053
13054 --------------------------------------------
13055 l_debug_info := 'Open Expense Lines Cursor';
13056 --------------------------------------------
13057 IF (AP_WEB_DB_EXPLINE_PKG.GetExpMileageLinesCursor(l_report_header_id, c_expense_lines_cursor)) THEN
13058
13059 LOOP
13060 --------------------------------------------
13061 l_debug_info := 'Fetch Mileage Lines Cursor';
13062 --------------------------------------------
13063 FETCH c_expense_lines_cursor INTO
13064 l_temp_mileage_line_array(j).start_date,
13065 l_temp_mileage_line_array(j).end_date,
13066 l_temp_mileage_line_array(j).number_of_days,
13067 l_temp_mileage_line_array(j).orig_dist_line_number,
13068 l_temp_mileage_line_array(j).policy_id,
13069 l_temp_mileage_line_array(j).avg_mileage_rate,
13070 l_temp_mileage_line_array(j).distance_unit_code,
13071 l_temp_mileage_line_array(j).trip_distance,
13072 l_temp_mileage_line_array(j).daily_distance,
13073 l_temp_mileage_line_array(j).category_code,
13074 l_temp_mileage_line_array(j).reimbursement_currency_code,
13075 l_temp_mileage_line_array(j).amount,
13076 l_temp_mileage_line_array(j).number_people,
13077 l_temp_mileage_line_array(j).web_parameter_id,
13078 l_temp_mileage_line_array(j).rate_per_passenger,
13079 l_temp_mileage_line_array(j).attribute1,
13080 l_temp_mileage_line_array(j).attribute2 ,
13081 l_temp_mileage_line_array(j).attribute3 ,
13082 l_temp_mileage_line_array(j).attribute4 ,
13083 l_temp_mileage_line_array(j).attribute5 ,
13084 l_temp_mileage_line_array(j).attribute6 ,
13085 l_temp_mileage_line_array(j).attribute7 ,
13086 l_temp_mileage_line_array(j).attribute8 ,
13087 l_temp_mileage_line_array(j).attribute9 ,
13088 l_temp_mileage_line_array(j).attribute10 ,
13089 l_temp_mileage_line_array(j).attribute11 ,
13090 l_temp_mileage_line_array(j).attribute12 ,
13091 l_temp_mileage_line_array(j).attribute13 ,
13092 l_temp_mileage_line_array(j).attribute14 ,
13093 l_temp_mileage_line_array(j).attribute15 ,
13094 l_temp_mileage_line_array(j).report_line_id ;
13095 EXIT WHEN c_expense_lines_cursor%NOTFOUND;
13096 l_temp_mileage_line_array(j).report_header_id := l_report_header_id;
13097 l_temp_mileage_line_array(j).new_dist_line_number := l_temp_mileage_line_array(j).orig_dist_line_number;
13098 j := j+1;
13099 END LOOP;
13100 END IF;
13101
13102 l_mileage_array_count := c_expense_lines_cursor%ROWCOUNT;
13103
13104 IF (l_mileage_array_count > 0 ) THEN
13105 FOR j IN 1..l_mileage_array_count LOOP
13106 l_mileage_line_array(j).start_date := l_temp_mileage_line_array(j).start_date;
13107 l_mileage_line_array(j).end_date := l_temp_mileage_line_array(j).end_date;
13108 l_mileage_line_array(j).number_of_days:= l_temp_mileage_line_array(j).number_of_days;
13109 l_mileage_line_array(j).orig_dist_line_number:= l_temp_mileage_line_array(j).orig_dist_line_number;
13110 l_mileage_line_array(j).policy_id:= l_temp_mileage_line_array(j).policy_id;
13111 l_mileage_line_array(j).avg_mileage_rate:= l_temp_mileage_line_array(j).avg_mileage_rate;
13112 l_mileage_line_array(j).distance_unit_code:= l_temp_mileage_line_array(j).distance_unit_code;
13113 l_mileage_line_array(j).trip_distance:= l_temp_mileage_line_array(j).trip_distance;
13114 l_mileage_line_array(j).category_code:= l_temp_mileage_line_array(j).category_code;
13115 l_mileage_line_array(j).reimbursement_currency_code := l_temp_mileage_line_array(j).reimbursement_currency_code;
13116 l_mileage_line_array(j).amount := l_temp_mileage_line_array(j).amount;
13117 l_mileage_line_array(j).report_header_id := l_temp_mileage_line_array(j).report_header_id;
13118 l_mileage_line_array(j).new_dist_line_number := l_temp_mileage_line_array(j).new_dist_line_number;
13119 l_mileage_line_array(j).number_people := l_temp_mileage_line_array(j).number_people;
13120 l_mileage_line_array(j).web_parameter_id := l_temp_mileage_line_array(j).web_parameter_id;
13121 l_mileage_line_array(j).rate_per_passenger := l_temp_mileage_line_array(j).rate_per_passenger;
13122 l_mileage_line_array(j).attribute1 := l_temp_mileage_line_array(j).attribute1;
13123 l_mileage_line_array(j).attribute2 := l_temp_mileage_line_array(j).attribute2;
13124 l_mileage_line_array(j).attribute3 := l_temp_mileage_line_array(j).attribute3;
13125 l_mileage_line_array(j).attribute4 := l_temp_mileage_line_array(j).attribute4;
13126 l_mileage_line_array(j).attribute5 := l_temp_mileage_line_array(j).attribute5;
13127 l_mileage_line_array(j).attribute6 := l_temp_mileage_line_array(j).attribute6;
13128 l_mileage_line_array(j).attribute7 := l_temp_mileage_line_array(j).attribute7;
13129 l_mileage_line_array(j).attribute8 := l_temp_mileage_line_array(j).attribute8;
13130 l_mileage_line_array(j).attribute9 := l_temp_mileage_line_array(j).attribute9;
13131 l_mileage_line_array(j).attribute10 := l_temp_mileage_line_array(j).attribute10;
13132 l_mileage_line_array(j).attribute11 := l_temp_mileage_line_array(j).attribute11;
13133 l_mileage_line_array(j).attribute12 := l_temp_mileage_line_array(j).attribute12;
13134 l_mileage_line_array(j).attribute13 := l_temp_mileage_line_array(j).attribute13;
13135 l_mileage_line_array(j).attribute14 := l_temp_mileage_line_array(j).attribute14;
13136 l_mileage_line_array(j).attribute15 := l_temp_mileage_line_array(j).attribute15;
13137 l_mileage_line_array(j).report_line_id := l_temp_mileage_line_array(j).report_line_id;
13138 END loop;
13139
13140 FOR i IN 1..l_mileage_array_count LOOP
13141 --------------------------------------------
13142 l_debug_info := 'Start processing the mileage line';
13143 --------------------------------------------
13144 IF (l_mileage_line_array(i).category_code = 'MILEAGE') THEN
13145
13146 --------------------------------------------
13147 l_debug_info := 'Get distance UOM from schedule header';
13148 --------------------------------------------
13149 AP_WEB_DB_SCHLINE_PKG.getSchHeaderInfo(
13150 p_policy_id => l_mileage_line_array(i).policy_id,
13151 p_sh_distance_uom => l_sh_distance_uom,
13152 p_sh_currency_code => l_sh_currency_code,
13153 p_sh_distance_thresholds_flag => l_sh_distance_thresholds_flag);
13154
13155 IF (l_sh_distance_thresholds_flag = 'P') THEN
13156 AP_WEB_DB_USER_PREF_PKG.getCumulativeMileage(l_mileage_line_array(i).policy_id,
13157 l_mileage_line_array(i).start_date,
13158 l_mileage_line_array(i).end_date,
13159 l_employee_id,
13160 l_cumulative_mileage,
13161 l_period_id);
13162 ELSIF (l_sh_distance_thresholds_flag = 'T') THEN
13163 l_cumulative_mileage := 0.0;
13164 l_period_id := 0;
13165 END IF;
13166
13167 --------------------------------------------
13168 l_debug_info := 'Call getScheduleLine';
13169 --------------------------------------------
13170 getScheduleLineArray(l_report_header_id,
13171 l_mileage_line_array(i).orig_dist_line_number,
13172 l_employee_id,
13173 l_cumulative_mileage,
13174 l_schedule_line_array);
13175
13176 l_orig_distance_travel := l_mileage_line_array(i).trip_distance;
13177
13178 IF (l_schedule_line_array.COUNT > 1) THEN
13179
13180 processCrossThreshold(
13181 p_ml_index => i,
13182 p_sh_distance_uom => l_sh_distance_uom,
13183 p_sh_currency_code => l_sh_currency_code,
13184 p_schedule_line_array => l_schedule_line_array,
13185 p_mileage_line_array_count => l_mileage_array_count,
13186 p_cumulative_mileage => l_cumulative_mileage,
13187 p_mileage_line_array => l_mileage_line_array);
13188
13189 ELSIF (l_schedule_line_array.COUNT = 1 ) THEN
13190 -------------------------------------------
13191 l_debug_info := 'is distance within range';
13192 -------------------------------------------
13193 IF l_over_threshold_distance > 1 THEN
13194 l_mileage_line_array(i).trip_distance :=
13195 round(l_mileage_line_array(i).trip_distance -
13196 l_over_threshold_distance);
13197
13198 l_mileage_line_array(i).daily_distance :=
13199 round(l_mileage_line_array(i).trip_distance /
13200 l_mileage_line_array(i).number_of_days);
13201
13202 ELSE
13203
13204 l_mileage_line_array(i).daily_distance :=
13205 round(l_mileage_line_array(i).trip_distance /
13206 l_mileage_line_array(i).number_of_days);
13207
13208 END IF;
13209
13210 /* To determine whether the entire trip distance has met another
13211 * threshold, we compare the reimbursement amount to find it out.
13212 * By doing this, we can avoid the precision error especially
13213 * there is no limit on the precision of a rate when defining a
13214 * schedule.
13215 */
13216
13217 l_rate := l_schedule_line_array(1).rate;
13218
13219 IF (l_sh_distance_uom <> l_mileage_line_array(i).distance_unit_code) THEN
13220 IF ((l_sh_distance_uom = C_KILOMETERS) AND (l_mileage_line_array(i).distance_unit_code = C_MILES )) THEN
13221 l_rate := round(l_schedule_line_array(1).rate * MILES_TO_KILOMETERS, 6);
13222 ELSIF ((l_sh_distance_uom = C_MILES) AND (l_mileage_line_array(i).distance_unit_code = C_KILOMETERS)) THEN
13223 l_rate := round(l_schedule_line_array(1).rate * KILOMETERS_TO_MILES, 6);
13224 ELSIF ((l_sh_distance_uom = C_SWMILES) AND (l_mileage_line_array(i).distance_unit_code = C_KILOMETERS)) THEN
13225 l_rate := round(l_schedule_line_array(1).rate * KILOMETERS_TO_SWMILES, 6);
13226 ELSIF ((l_sh_distance_uom = C_KILOMETERS) AND (l_mileage_line_array(i).distance_unit_code = C_SWMILES)) THEN
13227 l_rate := round(l_schedule_line_array(1).rate * SWMILES_TO_KILOMETERS, 6);
13228 ELSIF ((l_sh_distance_uom = C_MILES) AND (l_mileage_line_array(i).distance_unit_code = C_SWMILES)) THEN
13229 l_rate := round(l_schedule_line_array(1).rate * SWMILES_TO_MILES, 6);
13230 ELSIF ((l_sh_distance_uom = C_SWMILES) AND (l_mileage_line_array(i).distance_unit_code = C_MILES)) THEN
13231 l_rate := round(l_schedule_line_array(1).rate * MILES_TO_SWMILES, 6);
13232 END IF;
13233 END IF;
13234
13235 /* Bug 3975334 : Rate per passenger logic needs to be added.
13236 rate_per_passenger will be 0 if the schedule
13237 does not have passengers_flag as 'Y'.
13238 Bug 6448540 : Add getAddonMileageRatesSum
13239 */
13240
13241 l_rate := l_rate + nvl((l_schedule_line_array(1).rate_per_passenger *
13242 l_mileage_line_array(i).number_people),0)+
13243 getAddonMileageRatesSum(l_mileage_line_array(i).report_header_id,
13244 l_mileage_line_array(i).orig_dist_line_number);
13245
13246 FND_CURRENCY.GET_INFO(
13247 l_mileage_line_array(i).reimbursement_currency_code,
13248 l_base_precision ,
13249 l_ext_precision ,
13250 l_base_min_acct_unit);
13251
13252 IF (round(l_rate * l_mileage_line_array(i).trip_distance,l_base_precision) <> l_mileage_line_array(i).amount) THEN
13253 -- update reimbursable amount (Rate)
13254
13255 l_new_rate := getRate(
13256 p_sh_distance_uom => l_sh_distance_uom,
13257 p_sh_currency_code => l_sh_currency_code,
13258 p_mileage_line => l_mileage_line_array(i),
13259 p_schedule_line => l_schedule_line_array(1));
13260
13261 /* Bug 3975334 : Rate per passenger logic needs to be added.
13262 rate_per_passenger will be 0 if the schedule
13263 does not have passengers_flag as 'Y'.
13264 */
13265
13266 l_new_rate := l_new_rate + nvl((l_schedule_line_array(1).rate_per_passenger *
13267 l_mileage_line_array(i).number_people),0)+
13268 getAddonMileageRatesSum(l_mileage_line_array(i).report_header_id,
13269 l_mileage_line_array(i).orig_dist_line_number);
13270
13271 /* Bug 3732690 : In ProcessMileageLines rounding the amount before calling
13272 updateExpenseMileageLines.
13273 */
13274
13275 l_mileage_line_array(i).amount :=
13276 AP_UTILITIES_PKG.AP_ROUND_CURRENCY(
13277 l_new_rate * l_mileage_line_array(i).trip_distance,
13278 l_mileage_line_array(i).reimbursement_currency_code);
13279
13280 l_mileage_line_array(i).receipt_currency_amount :=
13281 l_mileage_line_array(i).amount;
13282
13283 l_mileage_line_array(i).daily_amount :=
13284 AP_UTILITIES_PKG.AP_ROUND_CURRENCY(
13285 l_new_rate * l_mileage_line_array(i).trip_distance /
13286 l_mileage_line_array(i).number_of_days,
13287 l_mileage_line_array(i).reimbursement_currency_code);
13288
13289 l_mileage_line_array(i).avg_mileage_rate := l_new_rate;
13290
13291 l_mileage_line_array(i).new_dist_line_number :=
13292 l_mileage_line_array(i).orig_dist_line_number;
13293
13294 l_mileage_line_array(i).status := AP_WEB_DB_EXPLINE_PKG.C_Modified;
13295
13296
13297 END IF;
13298
13299 IF (l_mileage_line_array(i).distance_unit_code = C_MILES) THEN
13300 l_cumulative_mileage := round(((l_orig_distance_travel * MILES_TO_KILOMETERS) + l_cumulative_mileage),1);
13301 ELSIF (l_mileage_line_array(i).distance_unit_code = C_SWMILES) THEN
13302 l_cumulative_mileage := round(((l_orig_distance_travel * SWMILES_TO_KILOMETERS) + l_cumulative_mileage),1);
13303 ELSE
13304 l_cumulative_mileage := l_orig_distance_travel + l_cumulative_mileage;
13305 END IF;
13306
13307 END IF;
13308
13309
13310 IF (l_sh_distance_thresholds_flag = 'P') THEN
13311 updateCumulativeMileage(l_cumulative_mileage,
13312 l_period_id,
13313 l_employee_id);
13314
13315 END IF;
13316
13317 BEGIN
13318 SELECT CALCULATE_AMOUNT_FLAG
13319 INTO l_client_extension_enabled
13320 FROM ap_expense_report_params
13321 WHERE parameter_id = l_mileage_line_array(i).web_parameter_id;
13322 EXCEPTION WHEN OTHERS THEN
13323 l_client_extension_enabled := 'N';
13324 END;
13325 IF (l_client_extension_enabled = 'Y') THEN
13326
13327 Custom1_Array(1).value := l_mileage_line_array(i).attribute1;
13328 Custom1_Array(2).value := l_mileage_line_array(i).attribute2;
13329 Custom1_Array(3).value := l_mileage_line_array(i).attribute3;
13330 Custom1_Array(4).value := l_mileage_line_array(i).attribute4;
13331 Custom1_Array(5).value := l_mileage_line_array(i).attribute5;
13332 Custom1_Array(6).value := l_mileage_line_array(i).attribute6;
13333 Custom1_Array(7).value := l_mileage_line_array(i).attribute7;
13334 Custom1_Array(8).value := l_mileage_line_array(i).attribute8;
13335 Custom1_Array(9).value := l_mileage_line_array(i).attribute9;
13336 Custom1_Array(10).value := l_mileage_line_array(i).attribute10;
13337 Custom1_Array(11).value := l_mileage_line_array(i).attribute11;
13338 Custom1_Array(12).value := l_mileage_line_array(i).attribute12;
13339 Custom1_Array(13).value := l_mileage_line_array(i).attribute13;
13340 Custom1_Array(14).value := l_mileage_line_array(i).attribute14;
13341 Custom1_Array(15).value := l_mileage_line_array(i).attribute15;
13342
13343 AP_WEB_DFLEX_PKG.GetReceiptCustomFields(l_custom_array,
13344 1, -- from ap_web_oa_mainflow_pkg.validatereceiptline
13345 Custom1_Array,
13346 Custom2_Array,
13347 Custom3_Array,
13348 Custom4_Array,
13349 Custom5_Array,
13350 Custom6_Array,
13351 Custom7_Array,
13352 Custom8_Array,
13353 Custom9_Array,
13354 Custom10_Array,
13355 Custom11_Array,
13356 Custom12_Array,
13357 Custom13_Array,
13358 Custom14_Array,
13359 Custom15_Array
13360 );
13361
13362 -- Bug: 6476888, NO_DATA_FOUND, wrong index used.
13363 l_mileage_line.parameter_id := l_mileage_line_array(i).web_parameter_id;
13364 l_mileage_line.start_date := l_mileage_line_array(i).start_date;
13365 l_mileage_line.end_date := l_mileage_line_array(i).end_date;
13366 l_mileage_line.tripDistance := l_mileage_line_array(i).trip_distance;
13367 l_mileage_line.distanceUnitCode := l_mileage_line_array(i).distance_unit_code;
13368 l_mileage_line.amount := l_mileage_line_array(i).amount;
13369 l_mileage_line.mileageRate := l_mileage_line_array(i).avg_mileage_rate; -- ?? base rate?
13370 l_mileage_line.numberPassengers := l_mileage_line_array(i).number_people;
13371 l_mileage_line.passengerRateUsed := l_mileage_line_array(i).rate_per_passenger;
13372 l_mileage_line.currency_code := l_mileage_line_array(i).reimbursement_currency_code;
13373 l_mileage_line.category_code := l_mileage_line_array(i).category_code;
13374
13375 OPEN getAddonRates(l_mileage_line_array(i).report_line_id);
13376 k := 1;
13377 LOOP
13378 -- l_addon_rates(1) := 'FOREST_ROADS';
13379 FETCH getAddonRates INTO l_addon_rates(k);
13380 EXIT WHEN getAddonRates%NOTFOUND;
13381 k := k + 1;
13382 END LOOP;
13383 CLOSE getAddonRates;
13384
13385 -- Bug: 6617094, Expense Type not populated for CustomCalculateAmount.
13386 AP_WEB_DFLEX_PKG.PopulateExpTypeInLineRec(l_mileage_line);
13387 AP_WEB_CUST_DFLEX_PKG.CustomCalculateAmount( l_report_header_info -- can be null from wf perspective
13388 , l_mileage_line -- should contain all fields as defined in fdd
13389 , l_custom_array-- should contain all fields as defined in fdd
13390 , l_addon_rates -- should contain all fields as defined in fdd
13391 , p_cust_meals_amount => l_temp_array
13392 , p_cust_accommodation_amount => l_temp_array
13393 , p_cust_night_rate_amount => l_temp_array
13394 , p_cust_pdm_rate => l_temp_array);
13395 -- delete reference to temp array as this is used for per diem only
13396 -- deleting prevents inadvertent data corruption
13397 -- Bug: 6476888, VARRAY can be atomically null, CustomCalculateAmount need not initialize this for Mileage
13398 IF (l_temp_array is not null) THEN
13399 l_temp_array.delete; -- bug 5358186
13400 END IF;
13401 l_mileage_line_array(i).amount := l_mileage_line.amount;
13402 END IF; -- if client extension enabled
13403
13404 END IF; -- IF (category_code = 'MILEAGE')
13405 END LOOP;
13406
13407 AP_WEB_DB_EXPLINE_PKG.updateExpenseMileageLines(l_mileage_line_array, l_bHeaderUpdated);
13408
13409 -----------------------------------------------------------------------
13410 l_debug_info := 'update display_total item attribute if ap_expense_report_headers has been updated';
13411 -----------------------------------------------------------------------
13412 IF (l_bHeaderUpdated = TRUE) THEN
13413 IF (NOT AP_WEB_DB_EXPRPT_PKG.UpdateHeaderTotal(l_report_header_id)) THEN
13414 NULL;
13415 END IF;
13416
13417 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetHeaderTotal(l_report_header_id,
13418 l_total)) THEN
13419 NULL;
13420 END IF;
13421
13422 IF (NOT AP_WEB_DB_EXPRPT_PKG.GetReimbCurr(l_report_header_id,
13423 l_reimb_curr)) THEN
13424
13425 NULL;
13426 END IF;
13427
13428 l_total_dsp := to_char(l_total,
13429 FND_CURRENCY.Get_Format_Mask(l_reimb_curr,22));
13430
13431 WF_ENGINE.SetItemAttrText('APEXP',
13432 to_char(l_report_header_id),
13433 'DISPLAY_TOTAL',
13434 l_total_dsp || ' ' || l_reimb_curr);
13435
13436
13437 END IF;
13438 END IF;
13439
13440 EXCEPTION
13441 WHEN OTHERS THEN
13442 AP_WEB_DB_UTIL_PKG.RaiseException('ProcessMileageLines');
13443 APP_EXCEPTION.RAISE_EXCEPTION;
13444 END ProcessMileageLines;
13445
13446 -------------------------------------------------------------------------------
13447 PROCEDURE hasCompanyViolations( p_item_type IN VARCHAR2,
13448 p_item_key IN VARCHAR2,
13449 p_actid IN NUMBER,
13450 p_funmode IN VARCHAR2,
13451 p_result OUT NOCOPY VARCHAR2) IS
13452 -------------------------------------------------------------------------------
13453 l_debug_info VARCHAR2(200);
13454 l_violations_count NUMBER:=0;
13455 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
13456 BEGIN
13457
13458
13459 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start hasCompanyViolations');
13460
13461 IF (p_funmode = 'RUN') THEN
13462 ------------------------------------------------------------
13463 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
13464 ------------------------------------------------------------
13465 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
13466 p_item_key,
13467 'EXPENSE_REPORT_ID');
13468 ------------------------------------------------------
13469 l_debug_info := 'Select from ap_pol_violations table';
13470 ------------------------------------------------------
13471 --Bug 3581975:Select the policy lines with distribution_line_number > 0.
13472 SELECT count(*)
13473 INTO l_violations_count
13474 FROM ap_pol_violations
13475 WHERE report_header_id = l_report_header_id
13476 and distribution_line_number > 0;
13477
13478 IF (l_violations_count > 0) THEN
13479 p_result := 'COMPLETE:Y';
13480 WF_ENGINE.SetItemAttrText(p_item_type,
13481 p_item_key,
13482 'RULES_VIOLATED',
13483 'Y');
13484 ELSE
13485 p_result := 'COMPLETE:N';
13486 WF_ENGINE.SetItemAttrText(p_item_type,
13487 p_item_key,
13488 'RULES_VIOLATED',
13489 'Y');
13490 END IF;
13491
13492 ELSIF (p_funmode = 'CANCEL') THEN
13493 p_result := 'COMPLETE';
13494 END IF;
13495
13496 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end hasCompanyViolations');
13497
13498 EXCEPTION
13499 WHEN OTHERS THEN
13500 AP_WEB_DB_UTIL_PKG.RaiseException('hasCompanyViolations');
13501 APP_EXCEPTION.RAISE_EXCEPTION;
13502 END hasCompanyViolations;
13503
13504
13505 -------------------------------------------------------------------------------
13506 PROCEDURE GenerateAmountMsg(document_id IN VARCHAR2,
13507 display_type IN VARCHAR2,
13508 document IN OUT NOCOPY VARCHAR2,
13509 document_type IN OUT NOCOPY VARCHAR2) IS
13510
13511 l_colon NUMBER;
13512 l_itemtype VARCHAR2(7);
13513 l_itemkey VARCHAR2(15);
13514
13515 l_report_header_id AP_WEB_DB_EXPLINE_PKG.expLines_headerID;
13516 l_debug_info VARCHAR2(2000);
13517 l_msg VARCHAR2(2000);
13518 l_approver_id NUMBER;
13519 l_total NUMBER;
13520 l_currency VARCHAR2(25);
13521
13522 BEGIN
13523
13524 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateAmountMsg');
13525
13526 ------------------------------------------------------------
13527 l_debug_info := 'Decode document_id';
13528 ------------------------------------------------------------
13529 l_colon := instrb(document_id, ':');
13530 l_debug_info := ' First index: ' || to_char(l_colon);
13531 l_itemtype := substrb(document_id, 1, l_colon - 1);
13532 l_itemkey := substrb(document_id, l_colon + 1);
13533
13534 ------------------------------------------------------
13535 l_debug_info := 'Retrieve Approve_ID Item Attribute';
13536 ------------------------------------------------------
13537 l_approver_id := WF_ENGINE.GetItemAttrNumber(l_itemtype,
13538 l_itemkey,
13539 'APPROVER_ID');
13540
13541 ------------------------------------------------------
13542 l_debug_info := 'Retrieve TOTAL Item Attribute';
13543 ------------------------------------------------------
13544 l_total := WF_ENGINE.GetItemAttrNumber(l_itemtype,
13545 l_itemkey,
13546 'TOTAL');
13547
13548 ------------------------------------------------------
13549 l_debug_info := 'Retrieve CURRENCY Item Attribute';
13550 ------------------------------------------------------
13551 l_currency := WF_ENGINE.GetItemAttrText(l_itemtype,
13552 l_itemkey,
13553 'CURRENCY');
13554
13555 l_msg := ap_web_amount_util.get_meaningful_amount_msg_emp(
13556 p_employee_id => l_approver_id,
13557 p_amount => l_total,
13558 p_date => SYSDATE,
13559 p_currency_code => l_currency);
13560
13561 document := l_msg;
13562 document_type := display_type;
13563
13564 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateExpLines');
13565
13566 EXCEPTION
13567 WHEN OTHERS THEN
13568 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateAmountMsg',
13569 document_id, l_debug_info);
13570 raise;
13571 END GenerateAmountMsg;
13572
13573 -------------------------------------------------------------------------------
13574 PROCEDURE GetRespAppInfo(p_item_key IN VARCHAR2,
13575 p_resp_id OUT NOCOPY NUMBER,
13576 P_appl_id OUT NOCOPY NUMBER) IS
13577 -------------------------------------------------------------------------------
13578 l_debug_info VARCHAR2(2000);
13579
13580 BEGIN
13581
13582 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetRespAppInfo');
13583
13584 ------------------------------------------------------
13585 l_debug_info := 'Retrieve RESPONSIBILITY_ID Item Attribute';
13586 ------------------------------------------------------
13587 p_resp_id := WF_ENGINE.GetItemAttrNumber('APEXP',
13588 p_item_key,
13589 'RESPONSIBILITY_ID');
13590
13591 ------------------------------------------------------
13592 l_debug_info := 'Retrieve APPLICATION_ID Item Attribute';
13593 ------------------------------------------------------
13594 p_appl_id := WF_ENGINE.GetItemAttrNumber('APEXP',
13595 p_item_key,
13596 'APPLICATION_ID');
13597
13598 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetRespAppInfo');
13599
13600 EXCEPTION
13601 WHEN OTHERS THEN
13602 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
13603 null;
13604 else
13605 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetRespAppInfo',
13606 p_item_key, l_debug_info);
13607 raise;
13608 end if;
13609 END GetRespAppInfo;
13610
13611 -------------------------------------------------------------------------------
13612 PROCEDURE GetAuditType( p_item_type IN VARCHAR2,
13613 p_item_key IN VARCHAR2,
13614 p_actid IN NUMBER,
13615 p_funmode IN VARCHAR2,
13616 p_result OUT NOCOPY VARCHAR2) IS
13617 -------------------------------------------------------------------------------
13618
13619 CURSOR audit_cur(p_report_header_id IN NUMBER) IS
13620 select audit_code
13621 from ap_expense_report_headers
13622 where report_header_id = p_report_header_id;
13623
13624 CURSOR rule_cur(p_report_header_id IN NUMBER) IS
13625 select rs.assign_auditor_stage_code
13626 from ap_expense_report_headers aerh,
13627 ap_aud_rule_sets rs,
13628 ap_aud_rule_assignments_all rsa
13629 where aerh.report_header_id = p_report_header_id
13630 and aerh.org_id = rsa.org_id
13631 and rsa.rule_set_id = rs.rule_set_id
13632 and rs.rule_set_type = 'RULE'
13633 and TRUNC(SYSDATE)
13634 BETWEEN TRUNC(NVL(rsa.START_DATE,SYSDATE))
13635 AND TRUNC(NVL(rsa.END_DATE,SYSDATE));
13636
13637 l_debug_info VARCHAR2(200);
13638 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
13639 audit_rec audit_cur%ROWTYPE;
13640 rule_rec rule_cur%ROWTYPE;
13641 BEGIN
13642
13643 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetAuditType');
13644
13645 IF (p_funmode = 'RUN') THEN
13646 ------------------------------------------------------------
13647 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
13648 ------------------------------------------------------------
13649 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
13650 p_item_key,
13651 'EXPENSE_REPORT_ID');
13652
13653 IF l_report_header_id IS NULL THEN
13654
13655 p_result := 'COMPLETE:AUDIT';
13656
13657 ELSE
13658
13659 ------------------------------------------------------------
13660 l_debug_info := 'Retrieve Expense Report audit type';
13661 ------------------------------------------------------------
13662 OPEN audit_cur(l_report_header_id);
13663 FETCH audit_cur INTO audit_rec;
13664
13665 IF audit_cur%NOTFOUND THEN
13666 p_result := 'COMPLETE:AUDIT';
13667 ELSIF audit_rec.audit_code is null THEN
13668 p_result := 'COMPLETE:AUDIT';
13669 ELSIF audit_rec.audit_code = 'PAPERLESS_AUDIT' THEN
13670
13671 OPEN rule_cur(l_report_header_id);
13672 FETCH rule_cur INTO rule_rec;
13673
13674 IF rule_cur%FOUND AND rule_rec.assign_auditor_stage_code = 'MANAGER_APPROVAL' THEN
13675 AP_WEB_AUDIT_QUEUE_UTILS.enqueue_for_audit(l_report_header_id);
13676 END IF;
13677
13678 CLOSE rule_cur;
13679
13680 p_result := 'COMPLETE:RULE_BASED_AUDIT';
13681 ELSIF audit_rec.audit_code = 'AUTO_APPROVE' THEN
13682 p_result := 'COMPLETE:AUTO_APPROVED';
13683 ELSIF audit_rec.audit_code = 'AUDIT' THEN
13684 p_result := 'COMPLETE:RULE_BASED_AUDIT';
13685 ELSE
13686 p_result := 'COMPLETE:AUDIT';
13687 END IF;
13688
13689 CLOSE audit_cur;
13690
13691 END IF;
13692
13693 ELSIF (p_funmode = 'CANCEL') THEN
13694 p_result := 'COMPLETE';
13695 END IF;
13696
13697 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetAuditType');
13698
13699 EXCEPTION
13700 WHEN OTHERS THEN
13701 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetAuditType',
13702 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
13703 raise;
13704 END GetAuditType;
13705
13706
13707 -------------------------------------------------------------------------------
13708 PROCEDURE ResetWFNote(p_item_type IN VARCHAR2,
13709 p_item_key IN VARCHAR2,
13710 p_actid IN NUMBER,
13711 p_funmode IN VARCHAR2,
13712 p_result OUT NOCOPY VARCHAR2) IS
13713 -------------------------------------------------------------------------------
13714
13715 l_debug_info VARCHAR2(200);
13716
13717 BEGIN
13718
13719
13720 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetWFNote');
13721
13722 ---------------------------------------------------------------
13723 l_debug_info := 'Reset WF_NOTE';
13724 ---------------------------------------------------------------
13725 WF_ENGINE.SetItemAttrText(p_item_type,
13726 p_item_key,
13727 'WF_NOTE',
13728 '');
13729
13730 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetWFNote');
13731
13732 EXCEPTION
13733 WHEN OTHERS THEN
13734 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ResetWFNote',
13735 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
13736 raise;
13737 END ResetWFNote;
13738
13739 ----------------------------------------------------------------------
13740 PROCEDURE AddToOtherErrors(p_item_type IN VARCHAR2,
13741 p_item_key IN VARCHAR2,
13742 p_other_error IN VARCHAR2) IS
13743 ----------------------------------------------------------------------
13744
13745 l_other_errors VARCHAR2(2000) := NULL;
13746
13747 l_prompts AP_WEB_UTILITIES_PKG.prompts_table;
13748 l_title AK_REGIONS_VL.name%TYPE;
13749
13750 l_debug_info VARCHAR2(2000);
13751
13752 BEGIN
13753
13754 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AddToOtherErrors');
13755
13756 ---------------------------------------------------------
13757 l_debug_info := 'Add to Other Errors';
13758 ---------------------------------------------------------
13759 l_other_errors := WF_ENGINE.GetItemAttrText(p_item_type,
13760 p_item_key,
13761 'OTHER_ERRORS');
13762 ---------------------------------------------------------
13763 l_debug_info := 'Check to see if error title needed';
13764 ---------------------------------------------------------
13765 if (l_other_errors IS NULL) then
13766 ---------------------------------------------------------
13767 l_debug_info := 'Add font tag';
13768 ---------------------------------------------------------
13769 l_other_errors := startOraFieldTextFont;
13770 else
13771 l_other_errors := l_other_errors || '<br>';
13772 end if;
13773
13774 AddToWFSSError(l_other_errors, p_other_error);
13775 l_other_errors := l_other_errors || endOraFieldTextFont;
13776
13777 WF_ENGINE.SetItemAttrText(p_item_type,
13778 p_item_key,
13779 'OTHER_ERRORS',
13780 l_other_errors);
13781
13782 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AddToOtherErrors');
13783
13784 EXCEPTION
13785 WHEN OTHERS THEN
13786 IF (SQLCODE <> -20001) THEN
13787 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
13788 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
13789 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'AddToOtherErrors');
13790 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
13791 END IF;
13792 APP_EXCEPTION.RAISE_EXCEPTION;
13793
13794 END AddToOtherErrors;
13795
13796 /*
13797 Written by:
13798 Ron Langi
13799 Purpose:
13800 To generate HEADER_ERRORS as a plsql doc attr since OWF.G no longer
13801 supports the use of html tags within a text item.
13802 */
13803 ----------------------------------------------------------------------
13804 PROCEDURE GenerateHeaderErrors(document_id IN VARCHAR2,
13805 display_type IN VARCHAR2,
13806 document IN OUT NOCOPY VARCHAR2,
13807 document_type IN OUT NOCOPY VARCHAR2) IS
13808 ----------------------------------------------------------------------
13809 l_colon NUMBER;
13810 l_itemtype VARCHAR2(7);
13811 l_itemkey VARCHAR2(25);
13812
13813 l_debug_info VARCHAR2(200);
13814
13815 BEGIN
13816 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GenerateHeaderErrors');
13817
13818 ------------------------------------------------------------
13819 l_debug_info := 'Decode document_id';
13820 ------------------------------------------------------------
13821 l_colon := instrb(document_id, ':');
13822 l_itemtype := substrb(document_id, 1, l_colon - 1);
13823 l_itemkey := substrb(document_id, l_colon + 1);
13824
13825 ------------------------------------------------------------
13826 l_debug_info := 'Retrieve HEADER_ERRORS Item Attribute';
13827 ------------------------------------------------------------
13828 document := WF_ENGINE.GetItemAttrText(l_itemtype,
13829 l_itemkey,
13830 'HEADER_ERRORS');
13831
13832 document_type := display_type;
13833
13834 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GenerateHeaderErrors');
13835
13836 EXCEPTION
13837 WHEN OTHERS THEN
13838 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GenerateHeaderErrors', document_id, l_debug_info);
13839 raise;
13840
13841 END GenerateHeaderErrors;
13842
13843
13844 /**
13845 * jrautiai ADJ Fix start
13846 */
13847 ----------------------------------------------------------------------
13848 PROCEDURE SetFromRoleAP(
13849 p_item_type IN VARCHAR2,
13850 p_item_key IN VARCHAR2,
13851 p_actid IN NUMBER,
13852 p_funmode IN VARCHAR2,
13853 p_result OUT NOCOPY VARCHAR2) IS
13854 ----------------------------------------------------------------------
13855 l_debug_info VARCHAR2(200);
13856 BEGIN
13857
13858 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetFromRoleAP');
13859
13860 IF (p_funmode = 'RUN') THEN
13861 ----------------------------------------------------------------
13862 l_debug_info := 'Set #FROM_ROLE to AP';
13863 ----------------------------------------------------------------
13864 SetFromRole(p_item_type,
13865 p_item_key,
13866 p_actid,
13867 WF_ENGINE.GetItemAttrText(p_item_type,
13868 p_item_key,
13869 'PAYABLES'),
13870 'SetFromRoleAP'
13871 );
13872 /*
13873 WF_ENGINE.SetItemAttrText(p_item_type,
13874 p_item_key,
13875 '#FROM_ROLE',
13876 WF_ENGINE.GetItemAttrText(p_item_type,
13877 p_item_key,
13878 'PAYABLES'));
13879 */
13880 p_result := 'COMPLETE:Y';
13881
13882 ELSIF (p_funmode = 'CANCEL') THEN
13883 p_result := 'COMPLETE';
13884 END IF;
13885
13886 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetFromRoleAP');
13887
13888 EXCEPTION
13889 WHEN OTHERS THEN
13890 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetFromRoleAP',
13891 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
13892 raise;
13893 END SetFromRoleAP;
13894
13895
13896 ------------------------------------------------------------------------
13897 PROCEDURE SetPolicyInfo(p_item_type IN VARCHAR2,
13898 p_item_key IN VARCHAR2,
13899 p_actid IN NUMBER,
13900 p_funmode IN VARCHAR2,
13901 p_result OUT NOCOPY VARCHAR2) IS
13902 -------------------------------------------------------------------------
13903 l_debug_info VARCHAR2(2000);
13904 BEGIN
13905
13906 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetPolicyInfo');
13907 SetShortPaidLinesInfo(p_item_type,
13908 p_item_key,
13909 p_actid,
13910 p_funmode,
13911 'POLICY',
13912 p_result);
13913 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetPolicyInfo');
13914
13915 EXCEPTION
13916 WHEN OTHERS THEN
13917 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetPolicyInfo',
13918 p_item_type, p_item_key, null, l_debug_info);
13919 raise;
13920 END SetPolicyInfo;
13921
13922 ------------------------------------------------------------------------
13923 PROCEDURE SetMissingReceiptInfo(p_item_type IN VARCHAR2,
13924 p_item_key IN VARCHAR2,
13925 p_actid IN NUMBER,
13926 p_funmode IN VARCHAR2,
13927 p_result OUT NOCOPY VARCHAR2) IS
13928 -------------------------------------------------------------------------
13929 l_debug_info VARCHAR2(2000);
13930 BEGIN
13931
13932 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetMissingReceiptInfo');
13933
13934 SetShortPaidLinesInfo(p_item_type,
13935 p_item_key,
13936 p_actid,
13937 p_funmode,
13938 'MISSING_RECEIPT',
13939 p_result);
13940 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetMissingReceiptInfo');
13941
13942 EXCEPTION
13943 WHEN OTHERS THEN
13944 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetMissingReceiptInfo',
13945 p_item_type, p_item_key, null, l_debug_info);
13946 raise;
13947 END SetMissingReceiptInfo;
13948
13949 ------------------------------------------------------------------------
13950 PROCEDURE SetProvideMissingInfo(p_item_type IN VARCHAR2,
13951 p_item_key IN VARCHAR2,
13952 p_actid IN NUMBER,
13953 p_funmode IN VARCHAR2,
13954 p_result OUT NOCOPY VARCHAR2) IS
13955 ------------------------------------------------------------------------
13956 l_debug_info VARCHAR2(2000);
13957 l_mess Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
13958 l_document_number AP_WEB_DB_EXPRPT_PKG.expHdr_invNum;
13959 l_preparer_name VARCHAR2(2000);
13960 BEGIN
13961
13962 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start SetProvideMissingInfo');
13963
13964
13965 ----------------------------------------------------------------
13966 l_debug_info := 'Set #FROM_ROLE to Preparer';
13967 ----------------------------------------------------------------
13968 SetFromRolePreparer(p_item_type, p_item_key, p_actid, p_funmode, p_result);
13969
13970 l_document_number := WF_ENGINE.GetItemAttrText(p_item_type,
13971 p_item_key,
13972 'DOCUMENT_NUMBER');
13973
13974 l_preparer_name := WF_ENGINE.GetItemAttrText(p_item_type,
13975 p_item_key,
13976 'PREPARER_DISPLAY_NAME');
13977
13978 FND_MESSAGE.SET_NAME('SQLAP','OIE_WF_PROVIDE_MISSING_NOTE');
13979 FND_MESSAGE.Set_Token('EMPLOYEE_NAME', l_preparer_name);
13980 FND_MESSAGE.Set_Token('REPORT_NUMBER', l_document_number);
13981 l_mess := FND_MESSAGE.GET;
13982
13983 WF_ENGINE.SetItemAttrText(p_item_type,
13984 p_item_key,
13985 'OIENOTES',
13986 l_mess);
13987
13988 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end SetProvideMissingInfo');
13989
13990 EXCEPTION
13991 WHEN OTHERS THEN
13992 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'SetProvideMissingInfo',
13993 p_item_type, p_item_key, null, l_debug_info);
13994 raise;
13995 END SetProvideMissingInfo;
13996
13997 PROCEDURE ResetShortpayAdjustmentInfo(p_item_type IN VARCHAR2,
13998 p_item_key IN VARCHAR2,
13999 p_actid IN NUMBER,
14000 p_funmode IN VARCHAR2,
14001 p_result OUT NOCOPY VARCHAR2) IS
14002 l_debug_info VARCHAR2(2000);
14003 l_report_header_id NUMBER;
14004 BEGIN
14005 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start ResetShortpayAdjustmentInfo');
14006
14007 ------------------------------------------------------------
14008 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
14009 ------------------------------------------------------------
14010 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
14011 p_item_key,
14012 'EXPENSE_REPORT_ID');
14013
14014 ----------------------------------------------------------------
14015 l_debug_info := 'Reset adjustment information';
14016 ----------------------------------------------------------------
14017 AP_WEB_DB_EXPLINE_PKG.ResetShortpayAdjustmentInfo(l_report_header_id);
14018
14019 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end ResetShortpayAdjustmentInfo');
14020 EXCEPTION
14021 WHEN OTHERS THEN
14022 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'ResetShortpayAdjustmentInfo',
14023 p_item_type, p_item_key, null, l_debug_info);
14024 raise;
14025 END ResetShortpayAdjustmentInfo;
14026
14027 /**
14028 * jrautiai ADJ Fix end
14029 */
14030
14031
14032 /*
14033 Written by:
14034 Ron Langi
14035 Purpose:
14036 To check the result of the Audit Review.
14037
14038 The possible results are:
14039 Reviewed - Auditor Complete
14040 Rejected - Auditor Rejected
14041 Request More Info - Auditor Requesting More Info
14042 */
14043 ----------------------------------------------------------------------
14044 PROCEDURE CheckAPReviewResult(
14045 p_item_type IN VARCHAR2,
14046 p_item_key IN VARCHAR2,
14047 p_actid IN NUMBER,
14048 p_funmode IN VARCHAR2,
14049 p_result OUT NOCOPY VARCHAR2) IS
14050 ----------------------------------------------------------------------
14051 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
14052 l_workflow_approved_flag AP_WEB_DB_EXPRPT_PKG.expHdr_wkflApprvdFlag;
14053
14054 l_return_reason VARCHAR2(80);
14055 l_return_instruction Wf_Item_Attribute_Values.TEXT_VALUE%TYPE;
14056
14057 l_debug_info VARCHAR2(200);
14058 BEGIN
14059
14060 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckAPReviewResult');
14061
14062
14063 IF (p_funmode = 'RUN') THEN
14064
14065 ----------------------------------------------------------------
14066 l_debug_info := 'Set #FROM_ROLE to AP';
14067 ----------------------------------------------------------------
14068 SetFromRoleAP(p_item_type, p_item_key, p_actid, p_funmode, p_result);
14069
14070 ------------------------------------------------------------
14071 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
14072 ------------------------------------------------------------
14073 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
14074 p_item_key,
14075 'EXPENSE_REPORT_ID');
14076
14077 ------------------------------------------------------------
14078 l_debug_info := 'Retrieve Return Reason and Instruction';
14079 ------------------------------------------------------------
14080 if (not AP_WEB_DB_EXPRPT_PKG.getAuditReturnReasonInstr(l_report_header_id,
14081 l_return_reason,
14082 l_return_instruction)) then
14083 l_debug_info := 'Could not retrieve Return Reason and Instruction';
14084 end if;
14085
14086 ----------------------------------------------------------
14087 l_debug_info := 'Set Item Attribute AUDIT_RETURN_REASON';
14088 ---------------------------------------------------------
14089 WF_ENGINE.SetItemAttrText(p_item_type,
14090 p_item_key,
14091 'AUDIT_RETURN_REASON',
14092 l_return_reason);
14093
14094 ----------------------------------------------------------
14095 l_debug_info := 'Set Item Attribute AUDIT_INSTRUCTIONS';
14096 ---------------------------------------------------------
14097 WF_ENGINE.SetItemAttrText(p_item_type,
14098 p_item_key,
14099 'AUDIT_INSTRUCTIONS',
14100 l_return_instruction);
14101
14102 ----------------------------------------------------------
14103 l_debug_info := 'Set Item Attribute Line_Info_Body';
14104 ---------------------------------------------------------
14105 WF_ENGINE.SetItemAttrText(p_item_type,
14106 p_item_key,
14107 'LINE_INFO_BODY',
14108 'plsql:AP_WEB_EXPENSE_WF.generateAdjustmentInfo/'|| p_item_type || ':' || p_item_key || ':AUDIT');
14109
14110 ------------------------------------------------------------
14111 l_debug_info := 'Retrieve Workflow_Approved_Flag';
14112 ------------------------------------------------------------
14113 SELECT WORKFLOW_APPROVED_FLAG
14114 INTO l_workflow_approved_flag
14115 FROM AP_EXPENSE_REPORT_HEADERS
14116 WHERE REPORT_HEADER_ID = l_report_header_id;
14117
14118 IF (l_workflow_approved_flag = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REJECTED) THEN
14119 p_result := 'COMPLETE:REJECTED';
14120 ELSIF (l_workflow_approved_flag = AP_WEB_DB_EXPRPT_PKG.C_WORKFLOW_APPROVED_REQUEST) THEN
14121 p_result := 'COMPLETE:REQUEST_MORE_INFO';
14122 ELSE
14123 p_result := 'COMPLETE:REVIEWED';
14124 END IF;
14125
14126 ELSIF (p_funmode = 'CANCEL') THEN
14127 NULL;
14128
14129 END IF;
14130
14131 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckAPReviewResult');
14132
14133 EXCEPTION
14134 WHEN OTHERS THEN
14135 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'CheckAPReviewResult',
14136 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
14137 raise;
14138 END CheckAPReviewResult;
14139
14140
14141 /*
14142 Written by:
14143 Ron Langi
14144 Purpose:
14145 This adds the expense report back to the Audit queue.
14146 */
14147 ----------------------------------------------------------------------
14148 PROCEDURE AddToAuditQueue(
14149 p_item_type IN VARCHAR2,
14150 p_item_key IN VARCHAR2,
14151 p_actid IN NUMBER,
14152 p_funmode IN VARCHAR2,
14153 p_result OUT NOCOPY VARCHAR2) IS
14154 ----------------------------------------------------------------------
14155 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
14156 l_debug_info VARCHAR2(200);
14157 l_manager_approved VARCHAR2(5);
14158 l_workflow_flag VARCHAR2(5);
14159
14160 CURSOR audit_cur(p_report_header_id IN NUMBER) IS
14161 select audit_code, workflow_approved_flag
14162 from ap_expense_report_headers
14163 where report_header_id = p_report_header_id;
14164
14165 audit_rec audit_cur%ROWTYPE;
14166
14167 BEGIN
14168
14169 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AddToAuditQueue');
14170
14171
14172 IF (p_funmode = 'RUN') THEN
14173
14174 ------------------------------------------------------------
14175 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
14176 ------------------------------------------------------------
14177 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
14178 p_item_key,
14179 'EXPENSE_REPORT_ID');
14180
14181 -------------------------------------------------------------------
14182 l_debug_info := 'Retrieve UPDATE_MANAGER_APPROVED Activity Attribute';
14183 -------------------------------------------------------------------
14184 l_manager_approved := WF_ENGINE.GetActivityAttrText(p_item_type,
14185 p_item_key,
14186 p_actid,
14187 'UPDATE_MANAGER_APPROVED');
14188
14189 ----------------------------------------------------------------------
14190 l_debug_info := 'Retrieve Expense Report audit type and workflow flag';
14191 ----------------------------------------------------------------------
14192 OPEN audit_cur(l_report_header_id);
14193 FETCH audit_cur INTO audit_rec;
14194
14195 IF l_manager_approved = 'Y' THEN
14196
14197 IF audit_rec.workflow_approved_flag in ('P','Y') THEN
14198 l_workflow_flag := 'Y';
14199 ELSE
14200 l_workflow_flag := 'M';
14201 END IF;
14202
14203 ----------------------------------------------------------------------
14204 l_debug_info := 'Update the Expense Report as Mgr Approved so that it can be auditable';
14205 ----------------------------------------------------------------------
14206 IF (NOT AP_WEB_DB_EXPRPT_PKG.SetWkflApprvdFlagAndSource(l_report_header_id,
14207 l_workflow_flag, NULL)) THEN
14208 NULL;
14209 END IF;
14210
14211 END IF;
14212
14213
14214 IF audit_rec.audit_code = 'PAPERLESS_AUDIT' THEN
14215 ------------------------------------------------------------
14216 l_debug_info := 'Add to Audit queue';
14217 ------------------------------------------------------------
14218 AP_WEB_AUDIT_QUEUE_UTILS.enqueue_for_audit(l_report_header_id);
14219 ELSIF audit_rec.audit_code = 'AUDIT' THEN
14220 ------------------------------------------------------------
14221 l_debug_info := 'Add to Audit queue';
14222 ------------------------------------------------------------
14223 --Bug#6618522
14224 AP_WEB_AUDIT_QUEUE_UTILS.assign_to_last_auditor(l_report_header_id);
14225 END IF;
14226
14227 CLOSE audit_cur;
14228
14229 p_result := 'COMPLETE:Y';
14230
14231 ELSIF (p_funmode = 'CANCEL') THEN
14232 NULL;
14233
14234 END IF;
14235
14236 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AddToAuditQueue');
14237
14238 EXCEPTION
14239 WHEN OTHERS THEN
14240 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AddToAuditQueue',
14241 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
14242 raise;
14243 END AddToAuditQueue;
14244
14245
14246 /*
14247 Written by:
14248 Ron Langi
14249 Purpose:
14250 This removes the expense report from the Audit queue.
14251 */
14252 ----------------------------------------------------------------------
14253 PROCEDURE RemoveFromAuditQueue(
14254 p_item_type IN VARCHAR2,
14255 p_item_key IN VARCHAR2,
14256 p_actid IN NUMBER,
14257 p_funmode IN VARCHAR2,
14258 p_result OUT NOCOPY VARCHAR2) IS
14259 ----------------------------------------------------------------------
14260 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
14261 l_debug_info VARCHAR2(200);
14262 BEGIN
14263
14264 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start RemoveFromAuditQueue');
14265
14266
14267 IF (p_funmode = 'RUN') THEN
14268
14269 ------------------------------------------------------------
14270 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
14271 ------------------------------------------------------------
14272 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
14273 p_item_key,
14274 'EXPENSE_REPORT_ID');
14275
14276 ------------------------------------------------------------
14277 l_debug_info := 'Remove from Audit queue';
14278 ------------------------------------------------------------
14279 AP_WEB_AUDIT_QUEUE_UTILS.remove_from_queue(l_report_header_id);
14280
14281 p_result := 'COMPLETE:Y';
14282
14283 ELSIF (p_funmode = 'CANCEL') THEN
14284 NULL;
14285
14286 END IF;
14287
14288 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end RemoveFromAuditQueue');
14289
14290 EXCEPTION
14291 WHEN OTHERS THEN
14292 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'RemoveFromAuditQueue',
14293 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
14294 raise;
14295 END RemoveFromAuditQueue;
14296
14297
14298 /*
14299 Written by:
14300 Ron Langi
14301 Purpose:
14302 This stores a Preparer-Auditor note based on the Manager/Preparer/Employee/Sysadmin
14303 action/response from a notification activity.
14304
14305 The following is gathered from the WF:
14306 - RESULT_TYPE contains the lookup type for the result of the Notification.
14307 - RESULT_CODE contains the lookup code for the result of the Notification.
14308 - RESPONSE contains the respond attr for the Notification.
14309
14310 The Preparer-Auditor note is stored in the form of:
14311 Preparer Response: <Preparer Response>
14312 or
14313 Employee Action: <Employee Response> (for 3rd Party Approval)
14314 or
14315 Approver Action: <Approver Response>
14316 or
14317 Sysadmin Action: <Sysadmin Response>
14318 */
14319 ----------------------------------------------------------------------
14320 PROCEDURE StoreNote(
14321 p_item_type IN VARCHAR2,
14322 p_item_key IN VARCHAR2,
14323 p_actid IN NUMBER,
14324 p_funmode IN VARCHAR2,
14325 p_result IN OUT NOCOPY VARCHAR2) IS
14326 ----------------------------------------------------------------------
14327 l_report_header_id AP_WEB_DB_EXPRPT_PKG.expHdr_headerID;
14328 l_debug_info VARCHAR2(200);
14329
14330 l_message_name fnd_new_messages.message_name%type;
14331 l_result_type varchar2(80);
14332 l_result_code varchar2(80);
14333 l_response varchar2(80);
14334 l_type_display_name varchar2(80);
14335 l_code_display_name varchar2(80);
14336 l_note_prefix varchar2(2000);
14337
14338 l_orig_language_code ap_expense_params.note_language_code%type := null;
14339 l_orig_language fnd_languages.nls_language%type := null;
14340 l_new_language_code ap_expense_params.note_language_code%type := null;
14341 l_new_language fnd_languages.nls_language%type := null;
14342
14343 l_entered_by NUMBER := fnd_global.user_id;
14344 l_user_name fnd_user.user_name%TYPE := null;
14345 l_ame_enabled varchar2(1) := 'N';
14346
14347 BEGIN
14348
14349 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start StoreNote');
14350
14351 IF (p_funmode = 'RUN') THEN
14352
14353 -------------------------------------------------------------------
14354 l_debug_info := 'Need to generate Note based on language setup';
14355 -------------------------------------------------------------------
14356
14357 -------------------------------------------------------------------
14358 l_debug_info := 'Save original language';
14359 -------------------------------------------------------------------
14360 l_orig_language_code := userenv('LANG');
14361 select nls_language
14362 into l_orig_language
14363 from fnd_languages
14364 where language_code = l_orig_language_code;
14365
14366 -------------------------------------------------------------------
14367 l_debug_info := 'Check AP_EXPENSE_PARAMS.NOTE_LANGUAGE_CODE';
14368 -------------------------------------------------------------------
14369 begin
14370 select note_language_code
14371 into l_new_language_code
14372 from ap_expense_params;
14373
14374 exception
14375 when no_data_found then
14376 null;
14377 end;
14378
14379 -------------------------------------------------------------------
14380 l_debug_info := 'Else use instance base language';
14381 -------------------------------------------------------------------
14382 if (l_new_language_code is null) then
14383 select language_code
14384 into l_new_language_code
14385 from fnd_languages
14386 where installed_flag in ('B');
14387 end if;
14388
14389 -------------------------------------------------------------------
14390 l_debug_info := 'Set nls context to new language';
14391 -------------------------------------------------------------------
14392 select nls_language
14393 into l_new_language
14394 from fnd_languages
14395 where language_code = l_new_language_code;
14396
14397 fnd_global.set_nls_context(p_nls_language => l_new_language);
14398
14399 -------------------------------------------------------------------
14400 l_debug_info := 'Retrieve Activity Result Type';
14401 -------------------------------------------------------------------
14402 l_result_type := WF_ENGINE.GetActivityAttrText(p_item_type,
14403 p_item_key,
14404 p_actid,
14405 'RESULT_TYPE');
14406
14407
14408 -------------------------------------------------------------------
14409 l_debug_info := 'Retrieve Note prefix';
14410 -------------------------------------------------------------------
14411 if (l_result_type = 'WFSTD_APPROVAL') then
14412 l_message_name := 'OIE_NOTES_APPROVER_ACTION';
14413 l_ame_enabled := nvl(WF_ENGINE.GetItemAttrText(p_item_type,
14414 p_item_key,
14415 'AME_ENABLED'),'N');
14416
14417 IF ( l_ame_enabled <> 'Y' ) THEN
14418
14419 BEGIN
14420 SELECT recipient_role INTO l_user_name
14421 FROM wf_notifications
14422 WHERE message_type = 'APEXP'
14423 AND message_name = 'OIE_REQ_EXPENSE_REPORT_APPRVL'
14424 AND ( item_key = p_item_key
14425 OR p_item_key = SubStr(context,7,length(p_item_key)) )
14426 AND status <> 'CANCELED';
14427
14428 AP_WEB_DB_HR_INT_PKG.GetUserIdFromName(l_user_name, l_entered_by);
14429 EXCEPTION
14430 WHEN OTHERS THEN
14431 l_entered_by := -1;
14432 END;
14433
14434 END IF;
14435
14436 IF ( l_ame_enabled = 'Y' OR l_entered_by = -1 ) THEN
14437 AP_WEB_OA_MAINFLOW_PKG.GetUserId(WF_ENGINE.GetItemAttrNumber(p_item_type,
14438 p_item_key,
14439 'APPROVER_ID'),
14440 l_entered_by);
14441 END IF;
14442 elsif (l_result_type = 'EMPLOYEE_APPROVAL') then
14443 l_message_name := 'OIE_NOTES_EMPLOYEE_ACTION';
14444 AP_WEB_OA_MAINFLOW_PKG.GetUserId(WF_ENGINE.GetItemAttrNumber(p_item_type,
14445 p_item_key,
14446 'EMPLOYEE_ID'),
14447 l_entered_by);
14448 -- EMPLOYEE_APPROVAL is to be treated the same as WFSTD_APPROVAL
14449 l_result_type := 'WFSTD_APPROVAL';
14450 else
14451 l_message_name := 'OIE_NOTES_PREPARER_RESPONSE';
14452 AP_WEB_OA_MAINFLOW_PKG.GetUserId(WF_ENGINE.GetItemAttrNumber(p_item_type,
14453 p_item_key,
14454 'PREPARER_ID'),
14455 l_entered_by);
14456 end if;
14457
14458 begin
14459 -------------------------------------------------------------------
14460 -- fnd_global.set_nls_context() seems to work for WF but not FND_MESSAGES
14461 -------------------------------------------------------------------
14462 select message_text
14463 into l_note_prefix
14464 from fnd_new_messages
14465 where application_id = 200
14466 and message_name = l_message_name
14467 and language_code = l_new_language_code;
14468
14469 exception
14470 when no_data_found then
14471 FND_MESSAGE.SET_NAME('SQLAP', l_message_name);
14472 l_note_prefix := FND_MESSAGE.GET;
14473 end;
14474
14475 -------------------------------------------------------------------
14476 l_debug_info := 'Retrieve Activity Result Code';
14477 -------------------------------------------------------------------
14478 l_result_code := WF_ENGINE.GetActivityAttrText(p_item_type,
14479 p_item_key,
14480 p_actid,
14481 'RESULT_CODE');
14482
14483 -------------------------------------------------------------------
14484 l_debug_info := 'Retrieve Activity Response';
14485 -------------------------------------------------------------------
14486 l_response := WF_ENGINE.GetActivityAttrText(p_item_type,
14487 p_item_key,
14488 p_actid,
14489 'RESPONSE');
14490
14491 ------------------------------------------------------------
14492 l_debug_info := 'Retrieve Expense_Report_ID Item Attribute';
14493 ------------------------------------------------------------
14494 l_report_header_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
14495 p_item_key,
14496 'EXPENSE_REPORT_ID');
14497
14498 ------------------------------------------------------------
14499 l_debug_info := 'Retrieve lookup display name';
14500 ------------------------------------------------------------
14501 WF_LOOKUP_TYPES_PUB.fetch_lookup_display(l_result_type,
14502 l_result_code,
14503 l_type_display_name,
14504 l_code_display_name);
14505
14506 ------------------------------------------------------------
14507 l_debug_info := 'store the result and response as a note';
14508 ------------------------------------------------------------
14509 AP_WEB_NOTES_PKG.CreateERPrepToAudNote (
14510 p_report_header_id => l_report_header_id,
14511 p_note => l_note_prefix||' '||l_code_display_name||'
14512 '||WF_ENGINE.GetItemAttrText(p_item_type, p_item_key, l_response),
14513 p_lang => l_new_language_code,
14514 p_entered_by => l_entered_by
14515 );
14516
14517 -------------------------------------------------------------------
14518 l_debug_info := 'Restore nls context to original language';
14519 -------------------------------------------------------------------
14520 fnd_global.set_nls_context(p_nls_language => l_orig_language);
14521
14522 -------------------------------------------------------------------
14523 -- only clear audit issues if it is a preparer response
14524 -------------------------------------------------------------------
14525 if (l_result_type <> 'WFSTD_APPROVAL') then
14526 ------------------------------------------------------------
14527 l_debug_info := 'clear the header/line level return/audit reason/instructions in AERH/AERL';
14528 ------------------------------------------------------------
14529 AP_WEB_DB_EXPRPT_PKG.clearAuditReturnReasonInstr(l_report_header_id);
14530 AP_WEB_DB_EXPLINE_PKG.clearAuditReturnReasonInstr(l_report_header_id);
14531
14532 ----------------------------------------------------------
14533 l_debug_info := 'clear Item Attribute AUDIT_RETURN_REASON';
14534 ---------------------------------------------------------
14535 WF_ENGINE.SetItemAttrText(p_item_type,
14536 p_item_key,
14537 'AUDIT_RETURN_REASON',
14538 '');
14539
14540 ----------------------------------------------------------
14541 l_debug_info := 'Set Item Attribute AUDIT_INSTRUCTIONS';
14542 ---------------------------------------------------------
14543 WF_ENGINE.SetItemAttrText(p_item_type,
14544 p_item_key,
14545 'AUDIT_INSTRUCTIONS',
14546 '');
14547 end if;
14548
14549 p_result := 'COMPLETE:Y';
14550
14551 END IF;
14552
14553 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end StoreNote');
14554
14555 EXCEPTION
14556 WHEN OTHERS THEN
14557 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'StoreNote',
14558 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
14559 raise;
14560 END StoreNote;
14561
14562
14563 --------------------------------------------------------------------------
14564
14565 /*Written By: Amulya Mishra
14566 Purpose : Notification Escalation project.
14567 Gets job level from HR for a person.
14568 */
14569 ----------------------------------------------------------------------
14570
14571 PROCEDURE GetJobLevelAndSupervisor(
14572 p_personId IN NUMBER,
14573 p_jobLevel OUT NOCOPY NUMBER)
14574 IS
14575 ----------------------------------------------------------------------
14576
14577 BEGIN
14578 SELECT
14579 nvl(pj.approval_authority, 0)
14580 INTO p_jobLevel
14581 FROM
14582 per_jobs pj,
14583 per_all_assignments_f pa
14584 WHERE
14585 pj.job_id = pa.job_id
14586 AND pa.person_id = p_personId
14587 AND pa.primary_flag = 'Y'
14588 AND pa.assignment_type in ('E' , 'C') --Support Contingent Workres
14589 AND pa.assignment_status_type_id not in
14590 (select assignment_status_type_id
14591 from per_assignment_status_types
14592 where per_system_status = 'TERM_ASSIGN')
14593 AND trunc(sysdate) between pa.effective_start_date and pa.effective_end_date;
14594
14595 EXCEPTION
14596 WHEN OTHERS THEN
14597 p_jobLevel := 0;
14598 end GetJobLevelAndSupervisor;
14599 ----------------------------------------------------------------------------
14600
14601
14602 ----------------------------------------------------------------------
14603 PROCEDURE IsEmployeeTerminated(p_item_type IN VARCHAR2,
14604 p_item_key IN VARCHAR2,
14605 p_actid IN NUMBER,
14606 p_funmode IN VARCHAR2,
14607 p_result OUT NOCOPY VARCHAR2) IS
14608 ----------------------------------------------------------------------
14609 l_person_id NUMBER := NULL;
14610
14611 fixable_exception EXCEPTION;
14612 l_error_message VARCHAR2(2000);
14613 l_debug_info VARCHAR2(200);
14614
14615 BEGIN
14616
14617 IF (p_funmode = 'RUN') THEN
14618
14619 ---------------------------------------------------------------
14620 l_debug_info := 'Retrieve Employee Id Item Attribute';
14621 ---------------------------------------------------------------
14622 l_person_id := WF_ENGINE.GetItemAttrText(p_item_type,
14623 p_item_key,
14624 'EMPLOYEE_ID');
14625
14626 -- Check whether person is terminated
14627 IF (AP_WEB_DB_HR_INT_PKG.isPersonTerminated(l_person_id)='Y') THEN
14628 p_result := 'COMPLETE:Y';
14629 ELSE
14630 p_result := 'COMPLETE:N';
14631 END IF;
14632
14633 ELSIF (p_funmode = 'CANCEL') THEN
14634 NULL;
14635 END IF;
14636
14637 EXCEPTION
14638 WHEN OTHERS THEN
14639 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsPersonTerminated',
14640 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
14641 raise;
14642 END IsEmployeeTerminated;
14643
14644
14645 ----------------------------------------------------------------------
14646 PROCEDURE IsEmployeeActive(p_item_type IN VARCHAR2,
14647 p_item_key IN VARCHAR2,
14648 p_actid IN NUMBER,
14649 p_funmode IN VARCHAR2,
14650 p_result OUT NOCOPY VARCHAR2) IS
14651 ----------------------------------------------------------------------
14652 l_person_id NUMBER := NULL;
14653
14654 fixable_exception EXCEPTION;
14655 l_error_message VARCHAR2(2000);
14656 l_debug_info VARCHAR2(200);
14657
14658 BEGIN
14659
14660 IF (p_funmode = 'RUN') THEN
14661
14662 ---------------------------------------------------------------
14663 l_debug_info := 'Retrieve Employee Id Item Attribute';
14664 ---------------------------------------------------------------
14665 l_person_id := WF_ENGINE.GetItemAttrText(p_item_type,
14666 p_item_key,
14667 'EMPLOYEE_ID');
14668
14669 -- Check whether person is active
14670 IF (AP_WEB_DB_HR_INT_PKG.isPersonActive(l_person_id)='Y') THEN
14671 p_result := 'COMPLETE:Y';
14672 ELSE
14673 p_result := 'COMPLETE:N';
14674 END IF;
14675
14676 ELSIF (p_funmode = 'CANCEL') THEN
14677 NULL;
14678 END IF;
14679
14680 EXCEPTION
14681 WHEN OTHERS THEN
14682 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsEmployeeActive',
14683 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
14684 raise;
14685 END IsEmployeeActive;
14686
14687 ----------------------------------------------------------------------
14688 PROCEDURE IsManagerActive(p_item_type IN VARCHAR2,
14689 p_item_key IN VARCHAR2,
14690 p_actid IN NUMBER,
14691 p_funmode IN VARCHAR2,
14692 p_result OUT NOCOPY VARCHAR2) IS
14693 ----------------------------------------------------------------------
14694 l_person_id NUMBER := NULL;
14695
14696 fixable_exception EXCEPTION;
14697 l_error_message VARCHAR2(2000);
14698 l_debug_info VARCHAR2(200);
14699
14700 BEGIN
14701
14702 IF (p_funmode = 'RUN') THEN
14703
14704 ---------------------------------------------------------------
14705 l_debug_info := 'Retrieve Manager Id Item Attribute';
14706 ---------------------------------------------------------------
14707 l_person_id := WF_ENGINE.GetItemAttrText(p_item_type,
14708 p_item_key,
14709 'MANAGER_ID');
14710
14711 -- Check whether person is active
14712 IF (AP_WEB_DB_HR_INT_PKG.isPersonActive(l_person_id)='Y') THEN
14713 p_result := 'COMPLETE:Y';
14714 ELSE
14715 p_result := 'COMPLETE:N';
14716 END IF;
14717
14718 ELSIF (p_funmode = 'CANCEL') THEN
14719 NULL;
14720 END IF;
14721
14722 EXCEPTION
14723 WHEN OTHERS THEN
14724 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsManagerActive',
14725 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
14726 raise;
14727 END IsManagerActive;
14728
14729
14730 -- 3257576 - Gets the manager info and sets p_error_message, p_instructions
14731 -- p_special_instr if manager is terminated or does not exist or is suspended
14732 ---------------------------------------------------------------------------
14733 PROCEDURE GetManagerInfoAndCheckStatus(
14734 p_employee_id IN NUMBER,
14735 p_employee_name IN VARCHAR2,
14736 p_manager_id OUT NOCOPY NUMBER,
14737 p_manager_name OUT NOCOPY VARCHAR2,
14738 p_manager_status OUT NOCOPY VARCHAR2,
14739 p_error_message OUT NOCOPY VARCHAR2,
14740 p_instructions OUT NOCOPY VARCHAR2,
14741 p_special_instr OUT NOCOPY VARCHAR2) IS
14742 ---------------------------------------------------------------------------
14743 l_debug_info VARCHAR2(200);
14744 l_emp_info_rec AP_WEB_DB_HR_INT_PKG.EmployeeInfoRec;
14745 l_employee_name per_workforce_x.full_name%TYPE;
14746 BEGIN
14747
14748 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start GetManagerInfoAndCheckStatus');
14749
14750 -----------------------------------------------------------
14751 l_debug_info := 'Trying to retrieve employee manager info';
14752 -----------------------------------------------------------
14753 AP_WEB_DB_HR_INT_PKG.GetManagerIdAndStatus(
14754 p_employee_id,
14755 p_manager_id,
14756 p_manager_name,
14757 p_manager_status);
14758
14759 -----------------------------------------------------------------------
14760 l_debug_info := 'After GetManagerIdAndStatus ' || to_char(p_manager_id)
14761 || 'p_manager_status '||p_manager_status;
14762 -----------------------------------------------------------------------
14763
14764 IF (p_manager_id IS NULL) THEN
14765 IF (p_employee_name IS NULL) THEN
14766 IF AP_WEB_DB_HR_INT_PKG.GetEmployeeInfo(p_employee_id,l_emp_info_rec) THEN
14767 l_employee_name := l_emp_info_rec.employee_name;
14768 END IF;
14769 END IF;
14770 --------------------------------
14771 l_debug_info := 'No supervisor';
14772 --------------------------------
14773 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_SUPERVISOR');
14774 FND_MESSAGE.Set_Token('EMPLOYEE_NAME', nvl(p_employee_name,l_employee_name));
14775 p_error_message := FND_MESSAGE.Get;
14776
14777 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR1');
14778 p_instructions := FND_MESSAGE.Get;
14779
14780 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_SPL_INSTR');
14781 p_special_instr := FND_MESSAGE.Get;
14782 ELSIF (p_manager_status = 'TERM_ASSIGN') THEN
14783 -----------------------------------------
14784 l_debug_info := 'Approver is terminated';
14785 -----------------------------------------
14786 FND_MESSAGE.Set_Name('SQLAP', 'OIE_APPROVER_TERMINATED');
14787 FND_MESSAGE.Set_Token('APPROVER_NAME', p_manager_name);
14788 p_error_message := FND_MESSAGE.Get;
14789
14790 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR1');
14791 p_instructions := FND_MESSAGE.Get;
14792
14793 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_SPL_INSTR');
14794 p_special_instr := FND_MESSAGE.Get;
14795 ELSIF ((p_manager_status = 'SUSP_ASSIGN') or
14796 (p_manager_status = 'SUSP_CWK_ASG')) THEN
14797 -----------------------------------------------------------
14798 l_debug_info := 'Approver is suspended/on temporary leave';
14799 -----------------------------------------------------------
14800 FND_MESSAGE.Set_Name('SQLAP', 'OIE_APPROVER_SUSPENDED');
14801 FND_MESSAGE.Set_Token('APPROVER_NAME', p_manager_name);
14802 p_error_message := FND_MESSAGE.Get;
14803
14804 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR2');
14805 p_instructions := FND_MESSAGE.Get;
14806
14807 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_SPL_INSTR');
14808 p_special_instr := FND_MESSAGE.Get;
14809 END IF;
14810
14811 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end GetManagerInfoAndCheckStatus');
14812
14813 EXCEPTION
14814 WHEN OTHERS THEN
14815 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'GetManagerInfoAndCheckStatus',
14816 null, null, null, l_debug_info);
14817 raise;
14818 END GetManagerInfoAndCheckStatus;
14819
14820 ----------------------------------------------------------------------------
14821 /* Written By : Amulya Mishra
14822 Bug 3389386: For Expense report with Both Pay only personal transactions,
14823 set the expense_status_code as PAID because the report gets
14824 automatically manager and payable approved and the header
14825 total is 0.
14826
14827 This is done inorder to avoid any usage of decode in files
14828 TrackExpenseReportsVO.xml and apwvw003.sql
14829 */
14830 ----------------------------------------------------------------------------
14831
14832 Procedure SetExpenseStatusCode(p_report_header_id IN Number)
14833 IS
14834 ----------------------------------------------------------------------------
14835 l_num_both_personal_lines NUMBER := 0;
14836
14837 BEGIN
14838
14839 IF (AP_WEB_DB_EXPLINE_PKG.GetNoOfBothPayPersonalLines(p_report_header_id,l_num_both_personal_lines)) THEN
14840 NULL;
14841 END IF;
14842
14843 IF l_num_both_personal_lines > 0 THEN
14844
14845 UPDATE AP_EXPENSE_REPORT_HEADERS
14846 SET EXPENSE_STATUS_CODE = 'PAID'
14847 WHERE REPORT_HEADER_ID = p_report_header_id;
14848
14849 END IF;
14850
14851
14852 END SetExpenseStatusCode;
14853 -----------------------------------------------------------------------------
14854
14855
14856 ----------------------------------------------------------------------------
14857 /* Written By : Amulya Mishra
14858 Bug 2777245: Update expense report header and lines data after submission
14859 through self-service and just before workflow kicks off.
14860
14861 Note: Customer can use this procedure to manipualte the values in
14862 Header and Lines table.
14863 */
14864 ----------------------------------------------------------------------------
14865
14866 Procedure UpdateHeaderLines(p_report_header_id IN Number)
14867 IS
14868 ----------------------------------------------------------------------------
14869
14870 BEGIN
14871
14872 UPDATE AP_EXPENSE_REPORT_HEADERS
14873 SET DESCRIPTION= AP_WEB_UTILITIES_PKG.RtrimMultiByteSpaces(description)
14874 WHERE REPORT_HEADER_ID = p_report_header_id;
14875
14876 UPDATE AP_EXPENSE_REPORT_LINES
14877 SET JUSTIFICATION = AP_WEB_UTILITIES_PKG.RtrimMultiByteSpaces(justification),
14878 SUBMITTED_AMOUNT = AMOUNT
14879 WHERE REPORT_HEADER_ID = p_report_header_id;
14880
14881 END UpdateHeaderLines;
14882
14883
14884 -----------------------------------------------------------------------------
14885 Procedure RaiseSubmitEvent(
14886 p_report_header_id IN Number,
14887 p_workflow_appr_flag IN VARCHAR2) IS
14888 ----------------------------------------------------------------------------
14889
14890 l_debug_info VARCHAR2(200);
14891
14892 l_user_id NUMBER;
14893 l_resp_id NUMBER;
14894 l_resp_appl_id NUMBER;
14895
14896 l_para_list WF_PARAMETER_LIST_T;
14897
14898 BEGIN
14899
14900 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start RaiseSubmitEvent');
14901
14902 ----------------------------------------------------------
14903 l_debug_info := 'Get USER_ID/RESP_ID/RESP_APPL_ID';
14904 ----------------------------------------------------------
14905 l_user_id := FND_PROFILE.VALUE('USER_ID');
14906 l_resp_id := FND_PROFILE.VALUE('RESP_ID');
14907 l_resp_appl_id := FND_PROFILE.VALUE('RESP_APPL_ID');
14908
14909 ----------------------------------------------------------
14910 l_debug_info := 'Add to event param list USER_ID/RESP_ID/RESP_APPL_ID';
14911 ----------------------------------------------------------
14912 wf_event.AddParameterToList(p_name =>'USER_ID',
14913 p_value =>l_user_id,
14914 p_parameterlist =>l_para_list);
14915
14916 wf_event.AddParameterToList(p_name =>'RESPONSIBILITY_ID',
14917 p_value =>l_resp_id,
14918 p_parameterlist =>l_para_list);
14919
14920 wf_event.AddParameterToList(p_name =>'APPLICATION_ID',
14921 p_value =>l_resp_appl_id,
14922 p_parameterlist =>l_para_list);
14923
14924 ----------------------------------------------------------
14925 l_debug_info := 'Raise Submit Event';
14926 ----------------------------------------------------------
14927 wf_event.raise(p_event_name => C_SUBMIT_EVENT_NAME,
14928 p_event_key => p_report_header_id,
14929 p_parameters => l_para_list);
14930
14931 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end RaiseSubmitEvent');
14932
14933 EXCEPTION
14934 WHEN OTHERS THEN
14935
14936 -- bug 2203689, set workflow_approved_flag to S so that users can
14937 -- re-submit the report without re-entering data again
14938
14939 -- Bug 3248874 : Also set expense_status_code as NULL.
14940 -- Source as NonValidateWebExpense.
14941
14942 UPDATE ap_expense_report_headers erh
14943 SET workflow_approved_flag = 'S',
14944 expense_status_code = null,
14945 source = 'NonValidatedWebExpense'
14946 WHERE report_header_id = p_report_header_id;
14947 COMMIT;
14948
14949
14950 IF (SQLCODE <> -20001) THEN
14951 FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
14952 FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
14953 FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'RaiseSubmitEvent');
14954 FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
14955 END IF;
14956
14957 -- always raise exceptions regardless it from RaiseSubmitEvent
14958 -- or other callees
14959 APP_EXCEPTION.RAISE_EXCEPTION;
14960
14961 END RaiseSubmitEvent;
14962
14963
14964 ----------------------------------------------------------------------
14965 PROCEDURE InitSubmit(
14966 p_item_type IN VARCHAR2,
14967 p_item_key IN VARCHAR2,
14968 p_actid IN NUMBER,
14969 p_funmode IN VARCHAR2,
14970 p_result IN OUT NOCOPY VARCHAR2) IS
14971 ----------------------------------------------------------------------
14972
14973 l_debug_info VARCHAR2(200);
14974
14975 l_report_header_id ap_expense_report_headers.report_header_id%type;
14976 l_preparer_id ap_expense_report_headers.employee_id%type;
14977 l_employee_id ap_expense_report_headers.employee_id%type;
14978 l_document_number ap_expense_report_headers.invoice_num%type;
14979 l_total ap_expense_report_lines.amount%type;
14980 l_new_total ap_expense_report_lines.amount%type;
14981 l_reimb_curr ap_expense_report_headers.default_currency_code%type;
14982 l_cost_center ap_expense_report_headers.flex_concatenated%type;
14983 l_purpose ap_expense_report_headers.description%type;
14984 l_approver_id ap_expense_report_headers.override_approver_id%type;
14985 l_week_end_date ap_expense_report_headers.week_end_date%type;
14986 l_workflow_flag ap_expense_report_headers.workflow_approved_flag%type;
14987 l_submit_from_oie varchar2(1);
14988
14989 BEGIN
14990
14991 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start InitSubmit');
14992
14993 l_report_header_id := to_number(p_item_key);
14994
14995 select aerh.report_header_id,
14996 fnd.employee_id,
14997 aerh.employee_id,
14998 aerh.invoice_num,
14999 aerh.default_currency_code,
15000 aerh.flex_concatenated,
15001 aerh.description,
15002 aerh.override_approver_id,
15003 aerh.week_end_date,
15004 aerh.workflow_approved_flag
15005 into l_report_header_id,
15006 l_preparer_id,
15007 l_employee_id,
15008 l_document_number,
15009 l_reimb_curr,
15010 l_cost_center,
15011 l_purpose,
15012 l_approver_id,
15013 l_week_end_date,
15014 l_workflow_flag
15015 from ap_expense_report_headers aerh,
15016 fnd_user fnd
15017 where aerh.report_header_id = l_report_header_id
15018 and fnd.user_id = aerh.created_by;
15019
15020 select sum(aerl.amount),
15021 sum(decode(sign(aerl.amount),-1,0,aerl.amount))
15022 into l_total,
15023 l_new_total
15024 from ap_expense_report_lines aerl
15025 where aerl.report_header_id = l_report_header_id
15026 and (itemization_parent_id is null OR itemization_parent_id <> -1);
15027
15028 StartExpenseReportProcess(
15029 l_report_header_id,
15030 l_preparer_id,
15031 l_employee_id,
15032 l_document_number,
15033 l_total,
15034 l_new_total,
15035 l_reimb_curr,
15036 l_cost_center,
15037 l_purpose,
15038 l_approver_id,
15039 l_week_end_date,
15040 l_workflow_flag,
15041 p_submit_from_oie => 'Y',
15042 p_event_raised => 'Y');
15043
15044 p_result := 'COMPLETE';
15045
15046 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end InitSubmit');
15047
15048 EXCEPTION
15049 WHEN OTHERS THEN
15050 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'InitSubmit',
15051 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15052 raise;
15053 END InitSubmit;
15054
15055 ------------------------------------------------------------------------
15056 FUNCTION CheckAccess(
15057 p_ntf_id IN NUMBER,
15058 p_item_key IN NUMBER,
15059 p_user_name IN VARCHAR2) RETURN VARCHAR2
15060 ------------------------------------------------------------------------
15061 IS
15062
15063 l_item_type wf_items.item_type%type;
15064 l_item_key wf_items.item_key%type;
15065 l_access_granted varchar2(1) := 'N';
15066 l_user_name wf_notifications.recipient_role%type;
15067
15068 BEGIN
15069
15070 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start CheckAccess');
15071
15072 -- get the item type for the notif
15073 select message_type
15074 into l_item_type
15075 from wf_notifications
15076 where notification_id = p_ntf_id
15077 and rownum = 1;
15078
15079 -- check the following:
15080 -- 1. NtfId is valid for ReportHeaderId
15081 if (l_item_type = 'APEXP') then
15082 --Bug 4425821: Uptake AME parallel approvers
15083 BEGIN
15084 select 'Y'
15085 into l_access_granted
15086 from wf_item_activity_statuses
15087 where item_type = l_item_type
15088 and ((item_key = to_char(p_item_key)) or (item_key like to_char(p_item_key) || '-%'))
15089 and notification_id = p_ntf_id
15090 and rownum = 1;
15091 EXCEPTION WHEN NO_DATA_FOUND THEN
15092 select 'Y'
15093 into l_access_granted
15094 from wf_item_activity_statuses_h
15095 where item_type = l_item_type
15096 and ((item_key = to_char(p_item_key)) or (item_key like to_char(p_item_key) || '-%'))
15097 and notification_id = p_ntf_id
15098 and rownum = 1;
15099 END;
15100
15101 elsif (l_item_type = 'APWHOLDS') then
15102
15103 BEGIN
15104 select item_key
15105 into l_item_key
15106 from wf_item_activity_statuses
15107 where item_type = l_item_type
15108 and notification_id = p_ntf_id
15109 and rownum = 1;
15110 EXCEPTION WHEN NO_DATA_FOUND THEN
15111 select item_key
15112 into l_item_key
15113 from wf_item_activity_statuses_h
15114 where item_type = l_item_type
15115 and notification_id = p_ntf_id
15116 and rownum = 1;
15117 END;
15118
15119 select 'Y'
15120 into l_access_granted
15121 from dual
15122 where
15123 (p_item_key = WF_ENGINE.GetItemAttrNumber(l_item_type, l_item_key, 'EXPENSE_REPORT_ID')
15124 or
15125 p_item_key = WF_ENGINE.GetItemAttrNumber(l_item_type, l_item_key, 'HOLDING_EXPENSE_REPORT_ID'))
15126 and rownum = 1;
15127
15128 elsif (l_item_type = 'APWRECPT') then
15129
15130 BEGIN
15131 select 'Y'
15132 into l_access_granted
15133 from wf_item_activity_statuses
15134 where item_type = l_item_type
15135 and item_key like '%'||to_char(p_item_key)||'%'
15136 and notification_id = p_ntf_id
15137 and rownum = 1;
15138 EXCEPTION WHEN NO_DATA_FOUND THEN
15139 select 'Y'
15140 into l_access_granted
15141 from wf_item_activity_statuses_h
15142 where item_type = l_item_type
15143 and item_key like '%'||to_char(p_item_key)||'%'
15144 and notification_id = p_ntf_id
15145 and rownum = 1;
15146 END;
15147 else
15148
15149 -- No Access
15150 RETURN l_access_granted;
15151
15152 end if;
15153
15154 /* bug 5360860: comment out as per wf dev product teams need not make this check
15155 as the check is already performed by Workflow UI and Workflow Mailer doesn't
15156 sends any emails to proxy user for the notification recieved by the originial
15157 recipient. */
15158 /*
15159 -- 2. User has access to the NtfId
15160 select 'Y'
15161 into l_access_granted
15162 from wf_notifications wfn ,
15163 WF_USER_ROLES wur
15164 where wur.user_name = p_user_name
15165 and wfn.notification_id = p_ntf_id
15166 and ( wfn.recipient_role = wur.role_name
15167 OR
15168 ( wfn.more_info_role is not null and wfn.more_info_role = wur.role_name )
15169 OR
15170 ( wfn.from_role is not null and wfn.from_role = wur.role_name ) )
15171 and rownum = 1;
15172 */
15173
15174 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end CheckAccess');
15175
15176 RETURN l_access_granted;
15177
15178 EXCEPTION
15179 WHEN NO_DATA_FOUND THEN
15180 RETURN 'N';
15181 WHEN OTHERS THEN
15182 RETURN 'N';
15183 END CheckAccess;
15184
15185 /*
15186 Bug 4425821: Uptake AME parallel approvers
15187 Called from AME Approval Process.
15188 Gets the next set of approvers, checks if Approval is complete,
15189 If yes return
15190 else spans 'AME Request Approval Process', copies attibute values from AME APproval
15191 process' to render the notification.
15192 */
15193 ----------------------------------------------------------------------
15194 PROCEDURE AMERequestApproval(p_item_type IN VARCHAR2,
15195 p_item_key IN VARCHAR2,
15196 p_actid IN NUMBER,
15197 p_funmode IN VARCHAR2,
15198 p_result OUT NOCOPY VARCHAR2) IS
15199 ----------------------------------------------------------------------
15200
15201 l_debug_info varchar2(200);
15202
15203 l_approvalProcessCompleteYNOut varchar2(1);
15204 l_nextApproversOut ame_util.approversTable2;
15205
15206 l_childItemKeySeq number;
15207 l_childItemKey wf_items.item_key%type;
15208 l_masterUserKey wf_items.user_key%type;
15209
15210 l_manager_name wf_users.name%type;
15211 l_manager_display_name wf_users.display_name%type;
15212
15213 l_master_report_id number;
15214
15215 fixable_exception EXCEPTION;
15216 l_error_message VARCHAR2(2000);
15217 l_instructions fnd_new_messages.message_text%type;
15218 l_special_instr fnd_new_messages.message_text%type;
15219 BEGIN
15220
15221 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMERequestApproval');
15222
15223 IF (p_funmode = 'RUN') THEN
15224
15225 -------------------------------------------------
15226 l_debug_info := 'Call AMEs getNextApprovers4 api';
15227 -------------------------------------------------
15228 BEGIN
15229 AME_API2.getNextApprovers4(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
15230 transactionTypeIn => p_item_type,
15231 transactionIdIn => p_item_key,
15232 approvalProcessCompleteYNOut => l_approvalProcessCompleteYNOut,
15233 nextApproversOut => l_nextApproversOut);
15234 EXCEPTION
15235 when others then
15236 FND_MESSAGE.Set_Name('SQLAP', 'OIE_GETNEXTAPPROVER_ERROR');
15237 l_error_message := FND_MESSAGE.Get;
15238 -- bug 3257576
15239 FND_MESSAGE.Set_Name('SQLAP', 'OIE_NO_APPROVER_INSTR4');
15240 l_instructions := FND_MESSAGE.Get;
15241 raise fixable_exception ;
15242 END;
15243
15244 IF (l_approvalProcessCompleteYNOut = ame_util.booleanTrue) THEN
15245 p_result := 'COMPLETE:Y';
15246 return;
15247 ELSIF (l_approvalProcessCompleteYNOut = ame_util2.completeNoApprovers) THEN
15248 p_result := 'COMPLETE:NOAPPROVER';
15249 return;
15250 END IF;
15251
15252 l_childItemKeySeq := WF_ENGINE.GetItemAttrNumber(p_item_type,
15253 p_item_key,
15254 'AME_CHILD_ITEM_KEY_SEQ');
15255
15256 FOR i IN 1 .. l_nextApproversOut.count LOOP
15257 IF (l_childItemKeySeq is null) THEN
15258 l_childItemKeySeq := 1;
15259 ELSE
15260 l_childItemKeySeq := l_childItemKeySeq + 1;
15261 END IF;
15262
15263 l_childItemKey := p_item_key || '-' || to_char(l_childItemKeySeq);
15264
15265 WF_ENGINE.CreateProcess(p_item_type,
15266 l_childItemKey,
15267 'AME_REQUEST_APPROVAL_PROCESS');
15268
15269 l_masterUserKey := WF_ENGINE.GetItemUserKey(p_item_type,
15270 p_item_key);
15271
15272 WF_ENGINE.SetItemUserKey(p_item_type,
15273 l_childItemKey,
15274 l_masterUserKey);
15275
15276
15277 if (l_nextApproversOut(i).orig_system = 'PER') then
15278 WF_DIRECTORY.GetUserName(l_nextApproversOut(i).orig_system,
15279 l_nextApproversOut(i).orig_system_id,
15280 l_manager_name,
15281 l_manager_display_name);
15282 else
15283 -- 6143415: To support position hierarchy
15284 WF_DIRECTORY.GetRoleName(l_nextApproversOut(i).orig_system,
15285 l_nextApproversOut(i).orig_system_id,
15286 l_manager_name,
15287 l_manager_display_name);
15288 end if;
15289
15290 --------------------------------------------------------
15291 l_debug_info := 'Set Approver_ID Info Item Attribute';
15292 --------------------------------------------------------
15293 WF_ENGINE.SetItemAttrText(p_item_type,
15294 l_childItemKey,
15295 'APPROVER_ID',
15296 l_nextApproversOut(i).orig_system_id);
15297
15298 --------------------------------------------------------
15299 l_debug_info := 'Set Approver_Name Info Item Attribute';
15300 --------------------------------------------------------
15301 WF_ENGINE.SetItemAttrText(p_item_type,
15302 l_childItemKey,
15303 'APPROVER_NAME',
15304 l_manager_name);
15305
15306 ----------------------------------------------------------------
15307 l_debug_info := 'Set Approver_Display_Name Info Item Attribute';
15308 ----------------------------------------------------------------
15309 WF_ENGINE.SetItemAttrText(p_item_type,
15310 l_childItemKey,
15311 'APPROVER_DISPLAY_NAME',
15312 l_manager_display_name);
15313 ----------------------------------------------------------------
15314 -- Bug 7272553: Store approver authority, used during reassign
15315 l_debug_info := 'Set Approver_Authority Info Item Attribute';
15316 ----------------------------------------------------------------
15317 begin
15318 WF_ENGINE.SetItemAttrText(p_item_type,
15319 l_childItemKey,
15320 'AME_APPROVER_AUTHORITY',
15321 l_nextApproversOut(i).authority);
15322 exception
15323 when others then
15324 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
15325 -- AME_APPROVER_AUTHORITY item attribute doesn't exist, need to add it
15326 WF_ENGINE.AddItemAttr(p_item_type, l_childItemKey, 'AME_APPROVER_AUTHORITY');
15327 WF_ENGINE.SetItemAttrNumber(p_item_type,
15328 l_childItemKey,
15329 'AME_APPROVER_AUTHORITY',
15330 l_nextApproversOut(i).authority);
15331 else
15332 raise;
15333 end if;
15334 end;
15335
15336 l_master_report_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
15337 p_item_key,
15338 'EXPENSE_REPORT_ID');
15339
15340
15341 WF_ENGINE.SetItemAttrText(p_item_type,
15342 l_childItemKey,
15343 'AME_MASTER_ITEM_KEY',
15344 p_item_key);
15345
15346 WF_ENGINE.SetItemAttrText(p_item_type,
15347 l_childItemKey,
15348 'AME_APPROVAL_TYPE',
15349 l_nextApproversOut(i).approver_category);
15350
15351 ----------------------------------------------------------------
15352 l_debug_info := 'Set wf attributes from the master process';
15353 ----------------------------------------------------------------
15354 BEGIN
15355 WF_ENGINE.SetItemAttrNumber(p_item_type,
15356 l_childItemKey,
15357 'ORG_ID',
15358 WF_ENGINE.GetItemAttrNumber(p_item_type,
15359 p_item_key,
15360 'ORG_ID'));
15361
15362 WF_ENGINE.SetItemAttrNumber(p_item_type,
15363 l_childItemKey,
15364 'USER_ID',
15365 WF_ENGINE.GetItemAttrNumber(p_item_type,
15366 p_item_key,
15367 'USER_ID'));
15368
15369 WF_ENGINE.SetItemAttrNumber(p_item_type,
15370 l_childItemKey,
15371 'RESPONSIBILITY_ID',
15372 WF_ENGINE.GetItemAttrNumber(p_item_type,
15373 p_item_key,
15374 'RESPONSIBILITY_ID'));
15375
15376 WF_ENGINE.SetItemAttrNumber(p_item_type,
15377 l_childItemKey,
15378 'APPLICATION_ID',
15379 WF_ENGINE.GetItemAttrNumber(p_item_type,
15380 p_item_key,
15381 'APPLICATION_ID'));
15382 EXCEPTION
15383 WHEN OTHERS THEN
15384 if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
15385 null;
15386 else
15387 raise;
15388 end if;
15389 END;
15390
15391 WF_ENGINE.SetItemAttrText(p_item_type,
15392 l_childItemKey,
15393 'AME_ENABLED',
15394 WF_ENGINE.GetItemAttrText(p_item_type,
15395 p_item_key,
15396 'AME_ENABLED'));
15397
15398 WF_ENGINE.SetItemAttrText(p_item_type,
15399 l_childItemKey,
15400 'WITHDRAW_WARNING',
15401 WF_ENGINE.GetItemAttrText(p_item_type,
15402 p_item_key,
15403 'WITHDRAW_WARNING'));
15404
15405 WF_ENGINE.SetItemAttrText(p_item_type,
15406 l_childItemKey,
15407 'GRANTS_ENABLED',
15408 WF_ENGINE.GetItemAttrText(p_item_type,
15409 p_item_key,
15410 'GRANTS_ENABLED'));
15411
15412 WF_ENGINE.SetItemAttrText(p_item_type,
15413 l_childItemKey,
15414 'LINE_TABLE',
15415 WF_ENGINE.GetItemAttrText(p_item_type,
15416 p_item_key,
15417 'LINE_TABLE'));
15418
15419 WF_ENGINE.SetItemAttrText(p_item_type,
15420 l_childItemKey,
15421 'EMP_LINE_TABLE',
15422 WF_ENGINE.GetItemAttrText(p_item_type,
15423 p_item_key,
15424 'EMP_LINE_TABLE'));
15425
15426 WF_ENGINE.SetItemAttrNumber(p_item_type,
15427 l_childItemKey,
15428 'EXPENSE_REPORT_ID',
15429 WF_ENGINE.GetItemAttrNumber(p_item_type,
15430 p_item_key,
15431 'EXPENSE_REPORT_ID'));
15432
15433 WF_ENGINE.SetItemAttrText(p_item_type,
15434 l_childItemKey,
15435 'DOCUMENT_NUMBER',
15436 WF_ENGINE.GetItemAttrText(p_item_type,
15437 p_item_key,
15438 'DOCUMENT_NUMBER'));
15439
15440 WF_ENGINE.SetItemAttrNumber(p_item_type,
15441 l_childItemKey,
15442 'PREPARER_ID',
15443 WF_ENGINE.GetItemAttrNumber(p_item_type,
15444 p_item_key,
15445 'PREPARER_ID'));
15446
15447 WF_ENGINE.SetItemAttrText(p_item_type,
15448 l_childItemKey,
15449 'PREPARER_NAME',
15450 WF_ENGINE.GetItemAttrText(p_item_type,
15451 p_item_key,
15452 'PREPARER_NAME'));
15453
15454 WF_ENGINE.SetItemAttrText(p_item_type,
15455 l_childItemKey,
15456 'PREPARER_DISPLAY_NAME',
15457 WF_ENGINE.GetItemAttrText(p_item_type,
15458 p_item_key,
15459 'PREPARER_DISPLAY_NAME'));
15460
15461 WF_ENGINE.SetItemAttrNumber(p_item_type,
15462 l_childItemKey,
15463 'EMPLOYEE_ID',
15464 WF_ENGINE.GetItemAttrNumber(p_item_type,
15465 p_item_key,
15466 'EMPLOYEE_ID'));
15467
15468 WF_ENGINE.SetItemAttrText(p_item_type,
15469 l_childItemKey,
15470 'EMPLOYEE_NAME',
15471 WF_ENGINE.GetItemAttrText(p_item_type,
15472 p_item_key,
15473 'EMPLOYEE_NAME'));
15474
15475 WF_ENGINE.SetItemAttrText(p_item_type,
15476 l_childItemKey,
15477 'EMPLOYEE_DISPLAY_NAME',
15478 WF_ENGINE.GetItemAttrText(p_item_type,
15479 p_item_key,
15480 'EMPLOYEE_DISPLAY_NAME'));
15481
15482 WF_ENGINE.SetItemAttrText(p_item_type,
15483 l_childItemKey,
15484 'PAYMENT_DUE_FROM',
15485 WF_ENGINE.GetItemAttrText(p_item_type,
15486 p_item_key,
15487 'PAYMENT_DUE_FROM'));
15488
15489 WF_ENGINE.SetItemAttrNumber(p_item_type,
15490 l_childItemKey,
15491 'TOTAL',
15492 WF_ENGINE.GetItemAttrNumber(p_item_type,
15493 p_item_key,
15494 'TOTAL'));
15495
15496 WF_ENGINE.SetItemAttrText(p_item_type,
15497 l_childItemKey,
15498 'DISPLAY_TOTAL',
15499 WF_ENGINE.GetItemAttrText(p_item_type,
15500 p_item_key,
15501 'DISPLAY_TOTAL'));
15502
15503 WF_ENGINE.SetItemAttrDate(p_item_type,
15504 l_childItemKey,
15505 'WEEK_END_DATE',
15506 WF_ENGINE.GetItemAttrDate(p_item_type,
15507 p_item_key,
15508 'WEEK_END_DATE'));
15509
15510 WF_ENGINE.SetItemAttrText(p_item_type,
15511 l_childItemKey,
15512 'EMPLOYEE_PROJECT_ENABLED',
15513 WF_ENGINE.GetItemAttrText(p_item_type,
15514 p_item_key,
15515 'EMPLOYEE_PROJECT_ENABLED'));
15516
15517 WF_ENGINE.SetItemAttrText(p_item_type,
15518 l_childItemKey,
15519 'CURRENCY',
15520 WF_ENGINE.GetItemAttrText(p_item_type,
15521 p_item_key,
15522 'CURRENCY'));
15523
15524 WF_ENGINE.SetItemAttrText(p_item_type,
15525 l_childItemKey,
15526 'DOC_COST_CENTER',
15527 WF_ENGINE.GetItemAttrText(p_item_type,
15528 p_item_key,
15529 'DOC_COST_CENTER'));
15530
15531 WF_ENGINE.SetItemAttrText(p_item_type,
15532 l_childItemKey,
15533 'EMP_COST_CENTER',
15534 WF_ENGINE.GetItemAttrText(p_item_type,
15535 p_item_key,
15536 'EMP_COST_CENTER'));
15537
15538 WF_ENGINE.SetItemAttrText(p_item_type,
15539 l_childItemKey,
15540 'HEADER_ATTACHMENTS',
15541 WF_ENGINE.GetItemAttrText(p_item_type,
15542 p_item_key,
15543 'HEADER_ATTACHMENTS'));
15544
15545 WF_ENGINE.SetItemAttrText(p_item_type,
15546 l_childItemKey,
15547 'SUBMIT_FROM_OIE',
15548 WF_ENGINE.GetItemAttrText(p_item_type,
15549 p_item_key,
15550 'SUBMIT_FROM_OIE'));
15551
15552 WF_ENGINE.SetItemAttrText(p_item_type,
15553 l_childItemKey,
15554 'EXPENSE_DETAILS',
15555 WF_ENGINE.GetItemAttrText(p_item_type,
15556 p_item_key,
15557 'EXPENSE_DETAILS'));
15558
15559 WF_ENGINE.SetItemAttrText(p_item_type,
15560 l_childItemKey,
15561 'EMP_VIOLATION_NOTE',
15562 WF_ENGINE.GetItemAttrText(p_item_type,
15563 p_item_key,
15564 'EMP_VIOLATION_NOTE'));
15565
15566 WF_ENGINE.SetItemAttrText(p_item_type,
15567 l_childItemKey,
15568 'VIOLATION_NOTE',
15569 WF_ENGINE.GetItemAttrText(p_item_type,
15570 p_item_key,
15571 'VIOLATION_NOTE'));
15572
15573 WF_ENGINE.SetItemAttrText(p_item_type,
15574 l_childItemKey,
15575 'MILEAGE_NOTE',
15576 WF_ENGINE.GetItemAttrText(p_item_type,
15577 p_item_key,
15578 'MILEAGE_NOTE'));
15579
15580 WF_ENGINE.SetItemAttrText(p_item_type,
15581 l_childItemKey,
15582 'VERIFY_NOTE',
15583 WF_ENGINE.GetItemAttrText(p_item_type,
15584 p_item_key,
15585 'VERIFY_NOTE'));
15586
15587 WF_ENGINE.SetItemAttrText(p_item_type,
15588 l_childItemKey,
15589 'AUDIT_RETURN_REASON',
15590 WF_ENGINE.GetItemAttrText(p_item_type,
15591 p_item_key,
15592 'AUDIT_RETURN_REASON'));
15593
15594 WF_ENGINE.SetItemAttrText(p_item_type,
15595 l_childItemKey,
15596 'AUDIT_INSTRUCTIONS',
15597 WF_ENGINE.GetItemAttrText(p_item_type,
15598 p_item_key,
15599 'AUDIT_INSTRUCTIONS'));
15600
15601 WF_ENGINE.SetItemAttrText(p_item_type,
15602 l_childItemKey,
15603 'CASH_LINE_ERRORS_AP',
15604 WF_ENGINE.GetItemAttrText(p_item_type,
15605 p_item_key,
15606 'CASH_LINE_ERRORS_AP'));
15607
15608 WF_ENGINE.SetItemAttrText(p_item_type,
15609 l_childItemKey,
15610 'CASH_LINE_ERRORS_PREPARER',
15611 WF_ENGINE.GetItemAttrText(p_item_type,
15612 p_item_key,
15613 'CASH_LINE_ERRORS_PREPARER'));
15614
15615 WF_ENGINE.SetItemAttrText(p_item_type,
15616 l_childItemKey,
15617 'CCARD_LINE_ERRORS_AP',
15618 WF_ENGINE.GetItemAttrText(p_item_type,
15619 p_item_key,
15620 'CCARD_LINE_ERRORS_AP'));
15621
15622 WF_ENGINE.SetItemAttrText(p_item_type,
15623 l_childItemKey,
15624 'CCARD_LINE_ERRORS_PREPARER',
15625 WF_ENGINE.GetItemAttrText(p_item_type,
15626 p_item_key,
15627 'CCARD_LINE_ERRORS_PREPARER'));
15628
15629 WF_ENGINE.SetItemAttrText(p_item_type,
15630 l_childItemKey,
15631 'GEN_HEADER_ERRORS',
15632 WF_ENGINE.GetItemAttrText(p_item_type,
15633 p_item_key,
15634 'GEN_HEADER_ERRORS'));
15635
15636 WF_ENGINE.SetItemAttrText(p_item_type,
15637 l_childItemKey,
15638 'IS_DEFAULT_COST_CENTER_USED',
15639 WF_ENGINE.GetItemAttrText(p_item_type,
15640 p_item_key,
15641 'IS_DEFAULT_COST_CENTER_USED'));
15642
15643 WF_ENGINE.SetItemAttrText(p_item_type,
15644 l_childItemKey,
15645 'IS_PROJECTS_REPORT',
15646 WF_ENGINE.GetItemAttrText(p_item_type,
15647 p_item_key,
15648 'IS_PROJECTS_REPORT'));
15649
15650
15651
15652
15653 ----------------------------------------------------------------
15654 l_debug_info := 'StartProcess ChildItemKey: ' || l_childItemKey;
15655 ----------------------------------------------------------------
15656 WF_ENGINE.StartProcess(p_item_type,
15657 l_childItemKey);
15658
15659 END LOOP;
15660
15661 WF_ENGINE.SetItemAttrText(p_item_type,
15662 p_item_key,
15663 'AME_CHILD_ITEM_KEY_SEQ',
15664 l_childItemKeySeq);
15665
15666 p_result := 'COMPLETE:N';
15667
15668 ELSIF (p_funmode = 'CANCEL') THEN
15669 NULL;
15670 END IF;
15671
15672 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMERequestApproval');
15673
15674 EXCEPTION
15675 WHEN fixable_exception THEN
15676 -- bug 3257576
15677 WF_ENGINE.SetItemAttrText(p_item_type,
15678 p_item_key,
15679 'NO_APPROVER_PROBLEM',
15680 l_error_message);
15681 WF_ENGINE.SetItemAttrText(p_item_type,
15682 p_item_key,
15683 'NO_APPROVER_INSTRUCTIONS',
15684 l_instructions);
15685 WF_ENGINE.SetItemAttrText(p_item_type,
15686 p_item_key,
15687 'NO_APPROVER_SPECIAL_INSTR',
15688 l_special_instr);
15689
15690 p_result := 'COMPLETE:NOAPPROVER';
15691 WHEN OTHERS THEN
15692 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMERequestApproval',
15693 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15694 raise;
15695 END AMERequestApproval;
15696
15697 /*
15698 Bug 4425821: Uptake AME parallel approvers
15699 Called from AME Request Approval process.
15700 Checks and returns if Action/FYI notification to be sent to the approver.
15701 */
15702 ----------------------------------------------------------------------
15703 PROCEDURE AMEGetApprovalType(p_item_type IN VARCHAR2,
15704 p_item_key IN VARCHAR2,
15705 p_actid IN NUMBER,
15706 p_funmode IN VARCHAR2,
15707 p_result OUT NOCOPY VARCHAR2) IS
15708 ----------------------------------------------------------------------
15709
15710 l_debug_info varchar2(200);
15711 l_ActionOrFyi varchar2(1);
15712 BEGIN
15713
15714 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMEGetApprovalType');
15715
15716 IF (p_funmode = 'RUN') THEN
15717
15718 --------------------------------------------------------------
15719 l_debug_info := 'Retrieve AME approval category - Action/FYI';
15720 --------------------------------------------------------------
15721 l_ActionOrFyi := WF_ENGINE.GetItemAttrText(p_item_type,
15722 p_item_key,
15723 'AME_APPROVAL_TYPE');
15724
15725 IF (nvl(l_ActionOrFyi,'A') = 'A') THEN
15726 p_result := 'COMPLETE:A';
15727 ELSE
15728 p_result := 'COMPLETE:F';
15729 END IF;
15730
15731 ELSIF (p_funmode = 'CANCEL') THEN
15732 NULL;
15733 END IF;
15734
15735 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMEGetApprovalType');
15736
15737 EXCEPTION
15738 WHEN OTHERS THEN
15739 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMEGetApprovalType',
15740 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15741 raise;
15742 END AMEGetApprovalType;
15743
15744 /*
15745 Bug 4425821: Uptake AME parallel approvers
15746 Called from AME Request Approval Process.
15747 We get the approver response and update the attribute 'AME Approver Response'
15748 with approver response, which would be used in AME Approval Process'.
15749 Update AME of approver response.
15750 */
15751 ----------------------------------------------------------------------
15752 PROCEDURE AMEPropagateApprovalResult(p_item_type IN VARCHAR2,
15753 p_item_key IN VARCHAR2,
15754 p_actid IN NUMBER,
15755 p_funmode IN VARCHAR2,
15756 p_result OUT NOCOPY VARCHAR2) IS
15757 ----------------------------------------------------------------------
15758
15759 l_debug_info varchar2(200);
15760 l_AmeMasterItemKey varchar2(30);
15761 l_approverResponse varchar2(30);
15762 l_approver_id number;
15763 l_response varchar2(80);
15764 l_approvalStatusIn varchar2(20);
15765 l_approver_name varchar2(240);
15766
15767 l_approverIn ame_util.approverRecord2;
15768
15769 l_debug varchar2(3000);
15770 BEGIN
15771
15772 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMEPropagateApprovalResult');
15773
15774 IF (p_funmode = 'RUN') THEN
15775
15776 l_AmeMasterItemKey := WF_ENGINE.GetItemAttrText(p_item_type,
15777 p_item_key,
15778 'AME_MASTER_ITEM_KEY');
15779
15780 l_approverResponse := WF_ENGINE.GetItemAttrText(p_item_type,
15781 l_AmeMasterItemKey,
15782 'AME_APPROVER_RESPONSE');
15783
15784 l_response := WF_ENGINE.GetActivityAttrText(p_item_type,
15785 p_item_key,
15786 p_actid,
15787 'RESPONSE');
15788 --------------------------------------------------------------
15789 l_debug_info := 'l_response : '|| l_response ||
15790 'l_approverResponse : '|| l_approverResponse ||
15791 'l_AmeMasterItemKey : '|| l_AmeMasterItemKey;
15792 ---------------------------------------------------------------
15793
15794 IF ((l_approverResponse IS NULL) OR (l_approverResponse <> 'REJECTED'))
15795 AND (l_response IS NOT NULL) THEN
15796 WF_ENGINE.SetItemAttrText(p_item_type,
15797 l_AmeMasterItemKey,
15798 'AME_APPROVER_RESPONSE',
15799 l_response);
15800 IF (l_response = 'REJECTED') THEN
15801 WF_ENGINE.SetItemAttrText(p_item_type,
15802 l_AmeMasterItemKey,
15803 'AME_REJECTED_CHILD_ITEM_KEY',
15804 p_item_key);
15805 END IF;
15806 --Bug 6411930: copy approver display name and note from rejected
15807 --child to parent, they are used to display the information in the
15808 --rejection notif to the preparer
15809 WF_ENGINE.SetItemAttrText(p_item_type,
15810 l_AmeMasterItemKey,
15811 'APPROVER_ID',
15812 WF_ENGINE.GetItemAttrText(p_item_type,
15813 p_item_key,
15814 'APPROVER_ID'));
15815 WF_ENGINE.SetItemAttrText(p_item_type,
15816 l_AmeMasterItemKey,
15817 'APPROVER_NAME',
15818 WF_ENGINE.GetItemAttrText(p_item_type,
15819 p_item_key,
15820 'APPROVER_NAME'));
15821 WF_ENGINE.SetItemAttrText(p_item_type,
15822 l_AmeMasterItemKey,
15823 'APPROVER_DISPLAY_NAME',
15824 WF_ENGINE.GetItemAttrText(p_item_type,
15825 p_item_key,
15826 'APPROVER_DISPLAY_NAME'));
15827 WF_ENGINE.SetItemAttrText(p_item_type,
15828 l_AmeMasterItemKey,
15829 'WF_NOTE',
15830 WF_ENGINE.GetItemAttrText(p_item_type,
15831 p_item_key,
15832 'WF_NOTE'));
15833
15834 END IF;
15835
15836 ------------------------------------------------------
15837 l_debug_info := 'Retrieve Approver_ID Item Attribute';
15838 -------------------------------------------------------
15839 l_approver_id := WF_ENGINE.GetItemAttrNumber(p_item_type,
15840 l_AmeMasterItemKey,
15841 'APPROVER_ID');
15842
15843 ------------------------------------------------------
15844 l_debug_info := 'Retrieve Approver_ID Item Attribute';
15845 -------------------------------------------------------
15846 l_approver_name := WF_ENGINE.GetItemAttrText(p_item_type,
15847 p_item_key,
15848 'APPROVER_NAME');
15849
15850 IF (l_response = 'APPROVED') THEN
15851 l_approvalStatusIn := AME_UTIL.approvedStatus;
15852 ELSIF (l_response = 'REJECTED') THEN
15853 l_approvalStatusIn := AME_UTIL.rejectStatus;
15854 ELSIF (l_response = 'NO_RESPONSE') THEN
15855 l_approvalStatusIn := AME_UTIL.noResponseStatus;
15856 ELSIF (l_response = 'FYI') THEN
15857 l_approvalStatusIn := AME_UTIL.notifiedStatus;
15858 END IF;
15859
15860 ------------------------------------------------------------------------------------------
15861 l_debug_info := 'l_response:'|| l_response || 'l_approvalStatusIn:' || l_approvalStatusIn;
15862 ------------------------------------------------------------------------------------------
15863 IF (l_response <> 'FYI') THEN
15864
15865 ------------------------------------------------------
15866 l_debug_info := 'Call AME_API2.updateApprovalStatus ';
15867 ------------------------------------------------------
15868 l_approverIn.name := l_approver_name;
15869 --l_approverIn.orig_system := 'PER';
15870 --l_approverIn.orig_system_id := l_approver_id;
15871 l_approverIn.approval_status := l_approvalStatusIn;
15872
15873 AME_API2.updateApprovalStatus(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
15874 transactionTypeIn => p_item_type,
15875 transactionIdIn => l_AmeMasterItemKey,
15876 approverIn => l_approverIn);
15877 /*
15878 AME_API2.updateApprovalStatus2(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
15879 transactionIdIn => l_AmeMasterItemKey,
15880 approvalStatusIn => l_approvalStatusIn,
15881 approverNameIn => l_approver_name,
15882 transactionTypeIn => 'APEXP');
15883 */
15884 END IF;
15885
15886 ------------------------------------------------------
15887 l_debug_info := 'End AMEPropagateApprovalResult ' || l_AmeMasterItemKey ;
15888 ------------------------------------------------------
15889
15890 p_result := 'Y';
15891
15892 ELSIF (p_funmode = 'CANCEL') THEN
15893 NULL;
15894 END IF;
15895
15896 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMEPropagateApprovalResult');
15897
15898 EXCEPTION
15899 WHEN OTHERS THEN
15900 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMEPropagateApprovalResult',
15901 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15902 raise;
15903 END AMEPropagateApprovalResult;
15904
15905 /*
15906 Bug 4425821: Uptake AME parallel approvers
15907 Called from AME Approval Process.
15908 Checks for Approver Response which is tracked in attribute 'AME Approver Response'
15909 Result : Approve/Reject
15910 */
15911 ----------------------------------------------------------------------
15912 PROCEDURE AMEGetApprovalResult(p_item_type IN VARCHAR2,
15913 p_item_key IN VARCHAR2,
15914 p_actid IN NUMBER,
15915 p_funmode IN VARCHAR2,
15916 p_result OUT NOCOPY VARCHAR2) IS
15917 ----------------------------------------------------------------------
15918
15919 l_debug_info varchar2(200);
15920 l_approverResponse varchar2(30);
15921 BEGIN
15922
15923 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMEGetApprovalResult');
15924
15925 IF (p_funmode = 'RUN') THEN
15926
15927 --------------------------------------------------------------
15928 l_debug_info := 'Check Approver Response - APPROVED/REJECTED';
15929 --------------------------------------------------------------
15930 l_approverResponse := WF_ENGINE.GetItemAttrText(p_item_type,
15931 p_item_key,
15932 'AME_APPROVER_RESPONSE');
15933
15934 IF (l_approverResponse = 'APPROVED') THEN
15935 p_result := 'COMPLETE:APPROVED';
15936 ELSIF (l_approverResponse = 'REJECTED') THEN
15937 p_result := 'COMPLETE:REJECTED';
15938 ELSIF (l_approverResponse = 'FYI') THEN
15939 p_result := 'COMPLETE:FYI';
15940 ELSIF (l_approverResponse = 'NO_RESPONSE') THEN
15941 p_result := 'COMPLETE:NO_RESPONSE';
15942 END IF;
15943
15944 ELSIF (p_funmode = 'CANCEL') THEN
15945 NULL;
15946 END IF;
15947
15948 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMEGetApprovalResult');
15949
15950 EXCEPTION
15951 WHEN OTHERS THEN
15952 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMEGetApprovalResult',
15953 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
15954 raise;
15955 END AMEGetApprovalResult;
15956
15957 /*
15958 Bug 4425821: Uptake AME parallel approvers
15959 Called from AME Request Approval Process.
15960 Completes Block Activity in 'AME Approval Process'.
15961 */
15962 ----------------------------------------------------------------------
15963 PROCEDURE AMECompleteApproval(p_item_type IN VARCHAR2,
15964 p_item_key IN VARCHAR2,
15965 p_actid IN NUMBER,
15966 p_funmode IN VARCHAR2,
15967 p_result OUT NOCOPY VARCHAR2) IS
15968 ----------------------------------------------------------------------
15969
15970 l_debug_info varchar2(200);
15971 l_AmeMasterItemKey varchar2(30);
15972 l_err_name varchar2(30);
15973 l_err_msg varchar2(2000);
15974 l_err_stack varchar2(32000);
15975 l_check_error varchar2(1);
15976 l_result varchar2(1);
15977
15978 l_approvalProcessCompleteYNOut varchar2(1);
15979 l_nextApproversOut ame_util.approversTable2;
15980
15981 BEGIN
15982
15983 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMECompleteApproval');
15984
15985 IF (p_funmode = 'RUN') THEN
15986
15987 l_AmeMasterItemKey := WF_ENGINE.GetItemAttrText(p_item_type,
15988 p_item_key,
15989 'AME_MASTER_ITEM_KEY');
15990
15991 ------------------------------------------------------
15992 l_debug_info := 'Call CompleteActivity ' || l_AmeMasterItemKey ;
15993 ------------------------------------------------------
15994 begin
15995 WF_ENGINE.CompleteActivity(itemtype => p_item_type,
15996 itemkey => l_AmeMasterItemKey,
15997 activity => 'AME_APPROVAL_BLOCK',
15998 result => null);
15999 l_result := 'Y';
16000 exception
16001 WHEN others THEN
16002
16003 l_check_error := WF_ENGINE.GetActivityAttrText(p_item_type,
16004 p_item_key,
16005 p_actid,
16006 'CHECK_ERROR');
16007 if l_check_error = 'Y' then
16008 wf_core.get_error(l_err_name, l_err_msg, l_err_stack);
16009 if (l_err_name = 'WFENG_NOT_NOTIFIED') then
16010 l_result := 'N';
16011 else
16012 raise;
16013 end if;
16014 else
16015 -- if approval is complete, complete as 'Y' to avoid error notification
16016 -- from being sent to sysadmin
16017 AME_API2.getNextApprovers4(applicationIdIn => AP_WEB_DB_UTIL_PKG.GetApplicationID,
16018 transactionTypeIn => p_item_type,
16019 transactionIdIn => l_AmeMasterItemKey,
16020 approvalProcessCompleteYNOut => l_approvalProcessCompleteYNOut,
16021 nextApproversOut => l_nextApproversOut);
16022
16023 if (l_approvalProcessCompleteYNOut = ame_util.booleanTrue) then
16024 l_result := 'Y';
16025 else
16026 raise;
16027 end if; -- end if l_approvalProcessCompleteYNOut
16028 end if; -- end if l_check_error = 'Y'
16029
16030 end;
16031
16032
16033 ------------------------------------------------------
16034 l_debug_info := 'End CompleteActivity ' || l_AmeMasterItemKey ;
16035 ------------------------------------------------------
16036 if (nvl(l_result,'N') = 'N') then
16037 p_result := 'COMPLETE:N';
16038 else
16039 p_result := 'COMPLETE:Y';
16040 end if;
16041
16042 ELSIF (p_funmode = 'CANCEL') THEN
16043 NULL;
16044 END IF;
16045
16046 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMECompleteApproval');
16047
16048 EXCEPTION
16049 WHEN OTHERS THEN
16050 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMECompleteApproval',
16051 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
16052 raise;
16053 END AMECompleteApproval;
16054
16055 /*
16056 Bug 4425821: Uptake AME parallel approvers
16057 Called from AME Approval Process.
16058 Gets the current pending approvers, if the pending approvers is > 1 then
16059 set expense_current_approver_id to -99999, if there is only one pending
16060 approver then set expense_current_approver_id to the approver id.
16061 We need to set it to -99999 inorder to distinguish if there is a single or
16062 multiple current approvers, when displaying current approver in Track Submitted
16063 Expense Reports table in Home Page.
16064 */
16065 ----------------------------------------------------------------------
16066 PROCEDURE AMESetCurrentApprover(p_item_type IN VARCHAR2,
16067 p_item_key IN VARCHAR2,
16068 p_actid IN NUMBER,
16069 p_funmode IN VARCHAR2,
16070 p_result OUT NOCOPY VARCHAR2) IS
16071 ----------------------------------------------------------------------
16072 l_debug_info varchar2(200);
16073 l_approvalProcessCompleteYNOut varchar2(10);
16074 l_approversOut ame_util.approversTable2;
16075 l_report_header_id number;
16076 BEGIN
16077
16078 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start AMESetCurrentApprover');
16079
16080 IF (p_funmode = 'RUN') THEN
16081
16082 l_report_header_id := to_char(p_item_key);
16083 -------------------------------------------------------
16084 l_debug_info := 'Calling ame_api2.getpendingapprovers';
16085 -------------------------------------------------------
16086 ame_api2.getpendingapprovers(applicationidin => AP_WEB_DB_UTIL_PKG.GetApplicationID,
16087 transactiontypein => p_item_type,
16088 transactionidin => p_item_key,
16089 approvalprocesscompleteynout => l_approvalProcessCompleteYNOut,
16090 approversout => l_approversOut);
16091
16092 if (l_approversOut.count > 1) then
16093 UPDATE ap_expense_report_headers_all
16094 SET expense_current_approver_id = C_AME_MULTIPLE_CURR_APPROVER
16095 WHERE report_header_id = l_report_header_id;
16096 elsif (l_approversOut.count = 1) then
16097 UPDATE ap_expense_report_headers_all
16098 SET expense_current_approver_id = l_approversOut(1).orig_system_id
16099 WHERE report_header_id = l_report_header_id;
16100 end if;
16101
16102 p_result := 'COMPLETE';
16103
16104 ELSIF (p_funmode = 'CANCEL') THEN
16105 NULL;
16106 END IF;
16107
16108 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end AMESetCurrentApprover');
16109
16110 EXCEPTION
16111 WHEN OTHERS THEN
16112 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'AMESetCurrentApprover',
16113 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
16114 raise;
16115 END AMESetCurrentApprover;
16116
16117 ---------------------------------------------------------------------------
16118 FUNCTION IsExpAccountsUpdated(p_report_line_id IN NUMBER)
16119 RETURN VARCHAR2 IS
16120 -----------------------------------------------------------------------
16121 l_ExpAccountsUpdated VARCHAR2(10);
16122 BEGIN
16123
16124 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start IsExpAccountsUpdated');
16125
16126 select decode(nvl(preparer_modified_flag, 'N'), 'Y', AP_WEB_FND_LOOKUPS_PKG.getYesNoMeaning('Y'), null)
16127 into l_ExpAccountsUpdated
16128 from ap_exp_report_dists
16129 where report_line_id = p_report_line_id
16130 and rownum = 1;
16131
16132
16133 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end IsExpAccountsUpdated');
16134
16135 RETURN l_ExpAccountsUpdated;
16136
16137 EXCEPTION
16138 WHEN OTHERS THEN
16139 RETURN l_ExpAccountsUpdated;
16140 END IsExpAccountsUpdated;
16141
16142 FUNCTION getItemKey(p_notification_id IN NUMBER) RETURN VARCHAR2 IS
16143 l_context wf_notifications.context%type;
16144 l_temp_context wf_notifications.context%type;
16145 l_item_key wf_notifications.context%type;
16146 l_debug_info varchar2(200);
16147 BEGIN
16148 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'start getItemKey');
16149
16150 select context into l_context
16151 from wf_notifications
16152 where notification_id = p_notification_id;
16153
16154 --l_context would have something like 'APEXP:22591-2:579934'
16155
16156 l_temp_context := substr(l_context,instrb(l_context, ':')+1); --'22591-2:579934'
16157 l_item_key := substr(l_temp_context,1,instrb(l_temp_context, ':')-1); --'22591-2'
16158
16159 return l_item_key;
16160
16161 AP_WEB_UTILITIES_PKG.logProcedure('AP_WEB_EXPENSE_WF', 'end getItemKey');
16162 EXCEPTION
16163 WHEN OTHERS THEN
16164 AP_WEB_DB_UTIL_PKG.RaiseException('AP_WEB_EXPENSE_WF.getItemKey',
16165 l_debug_info);
16166 APP_EXCEPTION.RAISE_EXCEPTION;
16167 END getItemKey;
16168
16169 ----------------------------------------------------------------------
16170 PROCEDURE IsPreparerActive(p_item_type IN VARCHAR2,
16171 p_item_key IN VARCHAR2,
16172 p_actid IN NUMBER,
16173 p_funmode IN VARCHAR2,
16174 p_result OUT NOCOPY VARCHAR2) IS
16175 ----------------------------------------------------------------------
16176 l_person_id NUMBER := NULL;
16177
16178 l_debug_info VARCHAR2(200);
16179
16180 BEGIN
16181
16182 IF (p_funmode = 'RUN') THEN
16183
16184 ---------------------------------------------------------------
16185 l_debug_info := 'Retrieve Employee Id Item Attribute';
16186 ---------------------------------------------------------------
16187 l_person_id := WF_ENGINE.GetItemAttrText(p_item_type,
16188 p_item_key,
16189 'PREPARER_ID');
16190
16191 -- Check whether person is active
16192 IF (AP_WEB_DB_HR_INT_PKG.isPersonActive(l_person_id)='Y') THEN
16193 p_result := 'COMPLETE:Y';
16194 ELSE
16195 p_result := 'COMPLETE:N';
16196 END IF;
16197
16198 ELSIF (p_funmode = 'CANCEL') THEN
16199 NULL;
16200 END IF;
16201
16202 EXCEPTION
16203 WHEN OTHERS THEN
16204 Wf_Core.Context('AP_WEB_EXPENSE_WF', 'IsPreparerActive',
16205 p_item_type, p_item_key, to_char(p_actid), l_debug_info);
16206 raise;
16207 END IsPreparerActive;
16208
16209 END AP_WEB_EXPENSE_WF;