The following SQL provides a list of all expense reports. This report is essentially for auditors and administrators to find out how many reports are pending with manager or auditor.
The script takes 2 parameters
- Date from which the list has to be generated till date (date format is DD-MON-YYYY)
- The Set of Books name
| 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 | SELECTgsob.NAME"SOB Name", aeh.invoice_num "Report Number", ppx.full_name, ppx.employee_number,       (SELECTap_web_policy_utils.get_lookup_meaning ('EXPENSE REPORT STATUS',                                                       DECODE (ai.cancelled_date,                                                               NULL, aeh.expense_status_code,                                                               'CANCELLED'                                                              ))          FROMap_invoices_all ai         WHEREai.invoice_id(+) = aeh.vouchno) "Report status",       NVL (aeh.report_submitted_date, aeh.creation_date) "Report submitted on",       CASE          WHENNVL2 (aap.entered_date,                     'Y',                     'N'                    ) = 'Y'             THENaap.entered_date       END"Manager Approved on", aeh.expense_status_code, TRUNC (aeh.week_end_date) "Report entered date",       aca.employee_number "Auditor Emp Num", aca.full_name "Auditor Name", aca.entered_date "Audited on"  FROMgl_sets_of_books gsob,       ap_expense_report_headers_all aeh,       per_people_x ppx,       (SELECTROW_NUMBER () OVER (PARTITION BYsource_object_id ORDERBYnote_id DESC) srl, an.note_id, an.source_object_id, an.entered_by,               an.entered_date, ppx.employee_number, ppx.full_name          FROMap_notes an, fnd_user fu, per_people_x ppx         WHEREan.entered_by = fu.user_id           ANDfu.employee_id = ppx.person_id           ANDan.source_object_code = 'OIE_EXPENSE_REPORT'           ANDTO_CHAR (SUBSTR (an.notes_detail,                                1,                                24                               )) = 'Approver Action: Approve') aap,       (SELECTROW_NUMBER () OVER (PARTITION BYsource_object_id ORDERBYnote_id DESC) srl, ans.note_id, ans.source_object_id,               ans.entered_by, ans.entered_date, pplx.employee_number, pplx.full_name          FROMap_notes ans, fnd_user fur, per_people_x pplx         WHEREans.entered_by = fur.user_id           ANDfur.employee_id = pplx.person_id           ANDans.source_object_code = 'OIE_EXPENSE_REPORT'           ANDTO_CHAR (SUBSTR (ans.notes_detail,                                1,                                15                               )) = 'Complete Audit.') aca WHERE1 = 1   ANDaeh.report_header_id = aca.source_object_id(+)   ANDaeh.report_header_id = aap.source_object_id(+)   ANDaeh.employee_id = ppx.person_id   ANDgsob.set_of_books_id = aeh.set_of_books_id   -- AND aeh.expense_status_code NOT IN ('INVOICED', 'PAID', 'WITHDRAWN', 'REJECTED')   ANDNVL (aap.srl, 1) = 1   ANDNVL (aca.srl, 1) = 1   ANDaeh.creation_date > TO_DATE (:date_in_ddmonyyyy, 'DD-MON-YYYY')   ANDTRUNC (SYSDATE) BETWEENTRUNC (ppx.effective_start_date) ANDTRUNC (ppx.effective_end_date)   ANDgsob.NAMEIN:sob_name | 
The previous query only gives the report header details. If we want to include the line information such as, the amount, currency and distribution account, then the previous query will be modified into the one below.
| 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 | SELECTgsob.NAME, aeh.invoice_num "Report Number", ppx.full_name, ppx.employee_number,       (SELECTap_web_policy_utils.get_lookup_meaning ('EXPENSE REPORT STATUS',                                                       DECODE (ai.cancelled_date,                                                               NULL, aeh.expense_status_code,                                                               'CANCELLED'                                                              ))          FROMap_invoices_all ai         WHEREai.invoice_id(+) = aeh.vouchno) "Report status",       ael.currency_code, ael.amount, NVL (aeh.report_submitted_date, aeh.creation_date) "Report submitted on",       CASE          WHENNVL2 (aap.entered_date,                     'Y',                     'N'                    ) = 'Y'             THENaap.entered_date       END"Manager Approved on", gcc.concatenated_segments, aeh.expense_status_code, TRUNC (aeh.week_end_date) "Report entered date",       aca.employee_number "Auditor Emp Num", aca.full_name "Auditor Name", aca.entered_date "Audited on"  FROMgl_sets_of_books gsob,       ap_expense_report_headers_all aeh,       per_people_x ppx,       gl_code_combinations_kfv gcc,       ap_expense_report_lines_all ael,       (SELECTROW_NUMBER () OVER (PARTITION BYsource_object_id ORDERBYnote_id DESC) srl, an.note_id, an.source_object_id, an.entered_by,               an.entered_date, ppx.employee_number, ppx.full_name          FROMap_notes an, fnd_user fu, per_people_x ppx         WHEREan.entered_by = fu.user_id           ANDfu.employee_id = ppx.person_id           ANDan.source_object_code = 'OIE_EXPENSE_REPORT'           ANDTO_CHAR (SUBSTR (an.notes_detail,                                1,                                24                               )) = 'Approver Action: Approve') aap,       (SELECTROW_NUMBER () OVER (PARTITION BYsource_object_id ORDERBYnote_id DESC) srl, ans.note_id, ans.source_object_id,               ans.entered_by, ans.entered_date, pplx.employee_number, pplx.full_name          FROMap_notes ans, fnd_user fur, per_people_x pplx         WHEREans.entered_by = fur.user_id           ANDfur.employee_id = pplx.person_id           ANDans.source_object_code = 'OIE_EXPENSE_REPORT'           ANDTO_CHAR (SUBSTR (ans.notes_detail,                                1,                                15                               )) = 'Complete Audit.') aca,       ap_exp_report_dists_all ada WHEREael.report_header_id = aeh.report_header_id   ANDada.report_header_id = ael.report_header_id   ANDada.report_line_id = ael.report_line_id   ANDaeh.report_header_id = aca.source_object_id(+)   ANDaeh.report_header_id = aap.source_object_id(+)   ANDaeh.employee_id = ppx.person_id   ANDada.code_combination_id = gcc.code_combination_id   ANDgsob.set_of_books_id = aeh.set_of_books_id   -- AND aeh.attribute_category <> 'Credit Card Expenses'   --AND aeh.expense_status_code NOT IN ('INVOICED', 'PAID', 'WITHDRAWN', 'REJECTED')   ANDNVL (aap.srl, 1) = 1   ANDNVL (aca.srl, 1) = 1   ANDaeh.creation_date > TO_DATE (:date_in_ddmonyyyy, 'DD-MON-YYYY')   ANDTRUNC (SYSDATE) BETWEENTRUNC (ppx.effective_start_date) ANDTRUNC (ppx.effective_end_date)   ANDgsob.NAMEIN:sob_name | 
 
0 comments