Friday, July 3, 2015

Query: Job Work Preferences




select
    pjt.name                         "Job",
    --
    pdf.work_any_location            "All Locations",
    pdf.passport_required            "Passport Required",
    pdf.relocation_required          "Relocation Required",
    pdf.relocate_domestically        "Relocation for Position",
    pdf.travel_required              "Travel Required",
    pdf.work_duration                "Work Duration",
    pdf.work_hours                   "Work Hours",
    pdf.service_minimum              "Minimum Service",     -- lookup :per_lengths_of_service
    pdf.work_schedule                "Work Schedule",       -- lookup :per_work_schedule
    pdf.fte_capacity                 "FTE Capacity",        -- lookup :per_work_hours
    pdf.work_any_country             "All Countries",
    pdf.relocate_internationally     "Willing to Relocate ",
    pdf.other_requirements           "Required Locations",
    ptv1.territory_short_name        "Rquired Countries1",
    hrl1tl.location_code             "Location1",
    ptv2.territory_short_name        "Rquired Countries2",
    hrl2tl.location_code             "Location2",
    ptv3.territory_short_name        "Rquired Countries3",
    hrl3tl.location_code             "Location3",
    --
    pj.job_id
from
    per_deployment_factors pdf,
    per_jobs pj,
    per_jobs_tl pjt,
    fnd_territories_vl ptv1,
    fnd_territories_vl ptv2,
    fnd_territories_vl ptv3,
    hr_locations_no_join hrl1,
    hr_locations_no_join hrl2,
    hr_locations_no_join hrl3,
    hr_locations_all_tl hrl1tl,
    hr_locations_all_tl hrl2tl,
    hr_locations_all_tl hrl3tl
where
    1=1
and pdf.job_id = pj.job_id
and pj.job_id = pjt.job_id
and pjt.language = userenv('LANG')
and ptv1.territory_code(+) = pdf.country1
and ptv2.territory_code(+) = pdf.country2
and ptv3.territory_code(+) = pdf.country3
and hrl1.location_id(+) = pdf.location1
and hrl2.location_id(+) = pdf.location2
and hrl3.location_id(+) = pdf.location3
and hrl1.location_id = hrl1tl.location_id(+)
and hrl2.location_id = hrl2tl.location_id(+)
and hrl3.location_id = hrl3tl.location_id(+)
and decode (hrl1tl.location_id, null, '1', hrl1tl.language) = decode (hrl1tl.location_id, null, '1', userenv ('LANG'))
and decode (hrl2tl.location_id, null, '1', hrl2tl.language) = decode (hrl2tl.location_id, null, '1', userenv ('LANG'))
and decode (hrl3tl.location_id, null, '1', hrl3tl.language) = decode (hrl3tl.location_id, null, '1', userenv ('LANG'))
--
and pjt.name = 'AA900.Administrative Assistant'
order by
    1,2,3;

Query: Contracts




select
    per.employee_number                                                              "Employee Number",
    --
    per.full_name                                                                    "Full Name",
    con.reference                                                                    "Contract Reference",
    asg.assignment_number                                                            "Assignment Number",
    hr_person_type_usage_info.get_user_person_type (sysdate,per.person_id)           "Person Type",
    per.applicant_number                                                             "Applicant Number",
    pps.date_start                                                                   "Hire Date",
    substr (hr_general.decode_lookup('CONTRACT_TYPE', con.type), 1, 80)              "Contract Type",  
    substr (hr_general.decode_lookup('CONTRACT_STATUS', con.status),1,80)            "Contract Status",
    substr ( hr_general.decode_lookup('CONTRACT_STATUS_REASON',con.status_reason),1,80) "Contract Status Reason",
    con.description                                                                     "Contract Description",
    con.duration                                                                        "Duration",
    substr ( hr_general.decode_lookup ('QUALIFYING_UNITS',con.duration_units), 1,80)    "Duration Units",
    con.contractual_job_title                                                           "Contractual Job Title",
    con.parties                                                                         "Parties",
    substr (hr_general.decode_lookup ('CONTRACT_START_REASON',con.start_reason),1,80)   "Start Reason",
    substr (hr_general.decode_lookup ('CONTRACT_END_REASON',con.end_reason),1,80)       "End Reason",
    con.number_of_extensions                                                            "Number of Extensions",
    con.extension_reason                                                                "Extension Reason",
    con.extension_period                                                                "Extension Period",
    substr (hr_general.decode_lookup ('QUALIFYING_UNITS',con.extension_period_units),1,80)  "Extension Period Units",
    greatest (con.effective_start_date, per.effective_start_date)                   "Effective Start Date",
    least (con.effective_end_date, per.effective_end_date)                          "Effective End Date",
     substr( hr_general.decode_lookup ('DOCUMENT_STATUS',con.doc_status),1,80)      "Document Status",
    con.doc_status_change_date                                                      "Date of Change",
    fnd_attachment_util_pkg.get_atchmt_exists ('PER_CONTRACTS',
                             con.contract_id,null,null,null,null,
                            'PERWSCTR','O')                                         "Attachment Exists",
    --
    asg.people_group_id,
    per.business_group_id,
    per.person_id
from
    per_people_f per,
    per_assignments_f asg,
    per_person_types ppt,
    per_periods_of_service pps,
    per_contracts_f con,
    per_business_groups bg
where
    con.person_id(+) = per.person_id
and pps.person_id = per.person_id
and asg.person_id = per.person_id
and asg.assignment_type in ('E','C')
and ppt.person_type_id = per.person_type_id
and sysdate between asg.effective_start_date and asg.effective_end_date
and sysdate between per.effective_start_date and per.effective_end_date
and per.business_group_id = bg.business_group_id
--
and bg.name = 'Vision Corporation'
and per.employee_number='388'
order by
    1,2,3,4;

Query: Contract Details





select
    ppf.employee_number                                              "Employee Number",
    --
    pcf1.reference                                                                  "Reference",
    hr_contract_api.get_meaning (pcf1.type, 'CONTRACT_TYPE')                        "Type",
    hr_contract_api.get_meaning (pcf1.status, 'CONTRACT_STATUS')                    "Status",
    hr_contract_api.get_meaning (pcf1.status_reason, 'CONTRACT_STATUS_REASON')      "Status Reason",
    pcf1.description                                                                "Description",
    hr_contract_api.get_meaning (pcf1.doc_status,'DOCUMENT_STATUS')                 "Document Status",
    doc_status_change_date                                                          "Date of Change",
    hr_contract_api.get_active_start_date(pcf1.contract_id,sysdate,pcf1.status)     "Active Dates:Start",
    hr_contract_api.get_active_end_date(pcf1.contract_id,sysdate,pcf1.status)       "Active Dates: End",
    hr_contract_api.get_pps_start_date(pcf1.person_id,
                hr_contract_api.get_active_start_date(pcf1.contract_id,
                        sysdate,pcf1.status))                                       "Per of Ser Dates:From",
    hr_contract_api.get_pps_end_date ( pcf1.person_id,
                hr_contract_api.get_active_start_date(pcf1.contract_id,
                        sysdate,pcf1.status))                                       "Per of Ser Dates:To",  
    pcf1.duration                                                                   "Duration",
    hr_contract_api.get_meaning (pcf1.duration_units,'QUALIFYING_UNITS')            "Units",
    hr_contract_api.get_meaning (pcf1.start_reason,'CONTRACT_START_REASON')         "Start Reason",
    hr_contract_api.get_meaning (pcf1.end_reason,'CONTRACT_END_REASON')             "End Reason",
    pcf1.contractual_job_title                                                      "Contractual Job",
    pcf1.parties                                                                    "Parties",
    pcf1.extension_period                                                           "Extension Period",
    hr_contract_api.get_meaning (pcf1.extension_period_units,'QUALIFYING_UNITS')    "Extension Period Units",
    pcf1.extension_reason                                                           "Extension Reason",
    pcf1.number_of_extensions                                                       "Number of Extensions",
    pcf1.effective_start_date                                                       "Effective Dates : From",
    pcf1.effective_end_date                                                         "Effective Dates : TO",
    --
    pcf1.contract_id,
    pcf1.person_id,
    pcf1.business_group_id
from
    per_contracts_f pcf1,
    per_people_f ppf,
    per_business_groups bg
where
    1=1
and pcf1.person_id = ppf.person_id
and sysdate between ppf.effective_start_date and ppf.effective_end_date
and ppf.business_group_id = bg.business_group_id
--
and bg.name = 'Vision Corporation'
and ppf.employee_number='388'
order by
    1,2,3;

Query: Events and Booking



select
    hr.meaning                                              "Type",
    pe.date_start                                           "Date:Start",
    pe.date_end                                             "Date: End",
    pe.time_start                                           "Time:Start",
    pe.time_end                                             "Time:End",
    hotl.name                                               "Org Run By",
    hltl.location_code                                      "Location",
    hl.timezone_code                                        "TimeZone",
    pe.external_contact                                     "External Contact: Name",
    pe.contact_telephone_number                             "External contact:Telephone",
    pap.full_name                                           "Internal Contact:Name",
    nvl (pap.employee_number, pap.npw_number)               "Internal Contact:Number",
    (select full_name
        from per_all_people_f
        where person_id = pb.person_id
        and sysdate between effective_start_date and effective_end_date)        "Bookings Name",
    (select employee_number
        from per_all_people_f
        where person_id = pb.person_id
        and sysdate between effective_start_date and effective_end_date)        "Worker Number",
    (select applicant_number
        from per_all_people_f
        where person_id = pb.person_id
        and sysdate between effective_start_date and effective_end_date)        "Applicant Number",
    --
    pe.event_id,
    pe.business_group_id,
    pe.assignment_id
    --
from
    per_events pe,
    per_bookings pb,
    per_all_people_f pap,
    hr_lookups hr,
    hr_locations_all_tl hltl,
    hr_locations_no_join hl,
    hr_all_organization_units ho,
    hr_all_organization_units_tl hotl
where  
    1=1
and ho.organization_id = hotl.organization_id(+)
and pe.organization_run_by_id = ho.organization_id(+)
and pe.event_or_interview = 'E'
and pe.type = hr.lookup_code
and pe.event_id=pb.event_id
and hr.lookup_type =decode (pe.emp_or_apl, 'E', 'EMP_EVENT_TYPE','A', 'APL_EVENT_TYPE')
and pe.location_id = hl.location_id(+)
and pe.internal_contact_person_id = pap.person_id(+)
and pe.date_start between nvl (pap.effective_start_date, pe.date_start)
and nvl (pap.effective_end_date, pe.date_start)
and decode (hotl.organization_id, null, '1', hotl.language) = decode (hotl.organization_id, null, '1', userenv ('LANG'))
and hl.location_id = hltl.location_id(+)
and decode (hltl.location_id, null, '1', hltl.language) =decode (hltl.location_id, null, '1', userenv ('LANG'))
--
and hr.meaning = 'Orientation Day'
order by
    1,2,3,4,5

Query: Organization Manager




select
    org_tl.name                                                         "Organization",
    ppf.full_name                                                       "Manager",
    fnd_date.canonical_to_date (org_info2.org_information3)             "Start Date",
    fnd_date.canonical_to_date (org_info2.org_information4)             "End Date",
    --
    org.organization_id,
    org.business_group_id,
    ppf.person_id
from
    hr_all_organization_units org,
    hr_all_organization_units_tl org_tl,
    hr_organization_information org_info2,
    per_all_people_f ppf
where
    1=1
and org_info2.organization_id = org.organization_id
and org_info2.org_information_context = 'Organization Name Alias'
and org_info2.org_information2 = to_char (ppf.person_id(+))
and org.organization_id = org_tl.organization_id
and org_tl.language = userenv ('LANG')
and exists (select null
    from hr_org_info_types_by_class oitbc, hr_organization_information org_info
    where org_info.organization_id = org.organization_id
    and org_info.org_information_context = 'CLASS'
    and org_info.org_information2 = 'Y'
    and oitbc.org_classification = org_info.org_information1
    and oitbc.org_information_type = 'Organization Name Alias')
and (decode(hr_security.view_all,
        'Y', 'TRUE',
        hr_security.show_record('HR_ALL_ORGANIZATION_UNITS',org.organization_id)) = 'TRUE'
    and decode (hr_general.get_xbg_profile,
            'Y', org.business_group_id,
            hr_general.get_business_group_id) = org.business_group_id
    or decode (hr_security.view_all,
            'Y', 'TRUE',
            hr_security.show_record ('PER_ALL_PEOPLE_F',
                               ppf.person_id,
                               ppf.person_type_id,
                               ppf.employee_number,
                               ppf.applicant_number)) = 'TRUE'
        and decode(hr_general.get_xbg_profile,
                'Y', ppf.business_group_id,
                hr_general.get_business_group_id) = ppf.business_group_id)
--
and org_tl.name = 'Sales'
order by
    1,2

Query: People Assignment Salary - History





select
    ppf.employee_number                                                     "Employee Number",
    --
    ppp.change_date                                                         "From" ,
    decode (ppp.date_to,hr_general.end_of_time, to_date (null),ppp.date_to) "To",
    nvl(ppp.proposed_salary_n,0)-(lag(ppp.proposed_salary_n)
        over (order by ppp.change_date))                                    "Change Amount",
    round(((nvl(ppp.proposed_salary_n,0)-(lag(ppp.proposed_salary_n)
        over (order by ppp.change_date)))/ppp.proposed_salary_n)*100,0)     "Change %",
    ppp.proposed_salary_n                                                   "Salary",
    (ppp.proposed_salary_n*12)                                              "Annualized Salary",
    pet.input_currency_code                                                 "Currency",
    ppb.name                                                                "Salary Basis",
    hr_general.decode_lookup ('PER_SAL_PROPOSAL_STATUS',ppp.approved)       "Status",
    --
    ppp.pay_proposal_id
from
    per_pay_proposals ppp,
    per_performance_reviews ppr,
    per_assignments_f2 paa,
    per_people_f ppf,
    per_pay_bases ppb,
    pay_input_values_f piv,
    pay_element_types_f pet,
    fnd_currencies_tl fct,
    fnd_user fu
where  
    1=1
and ppp.performance_review_id = ppr.performance_review_id(+)
and paa.assignment_id = ppp.assignment_id
and paa.person_id = ppf.person_id
and ppp.last_updated_by = fu.user_id(+)
and ppp.change_date between paa.effective_start_date and paa.effective_end_date
and paa.pay_basis_id = ppb.pay_basis_id(+)
and per_saladmin_utility.get_currency (ppp.assignment_id,ppp.change_date) = fct.name
and fct.language = userenv ('LANG')
and fct.currency_code = pet.input_currency_code
and ppb.input_value_id = piv.input_value_id
and piv.element_type_id = pet.element_type_id
and ppp.assignment_id=12951
and ppp.change_date between piv.effective_start_date
and piv.effective_end_date
and ppp.change_date between pet.effective_start_date and pet.effective_end_date
--
and ppf.employee_number = '1309'
order by
    change_date desc;

Query: Salary Management





select
    ppf.employee_number                 "Employee Number",
    --
    ppf.full_name                         "Full Name",
    psf.assignment_number                 "Assignment Number",
    ppb.name                              "Salary basis",
    ppp.change_date                       "Approved Date",
    ppp.proposed_salary_n                 "Approved Salary",
    pro1.change_date                      "Change Date",
    pro1.proposed_salary_n                "Proposed Salary",
    proposal_reason                       "Proposal Reason",
    pppc.change_percentage                "COL %",
    pppc.change_amount_n                  "COL Amount",
    psf.employment_category               "Assignment Category",           -- lookup;EMP_CAT
    --
    ppf.person_id,
    ppb.pay_basis_id
from
     per_all_people_f ppf,
     per_assignments_f psf,
     per_pay_bases ppb,
      per_pay_proposals pro1,
     (select ppp.change_date,
                  ppp.proposed_salary_n,
                  ppp.approved,
                  ppp.assignment_id
             from per_pay_proposals ppp
            where approved = 'Y')  ppp,
    per_pay_proposal_components pppc        
where
    1=1
and ppf.person_id = psf.person_id
and psf.pay_basis_id = ppb.pay_basis_id
and psf.assignment_id = pro1.assignment_id(+)
and pro1.approved(+) = 'N'
and psf.assignment_id = ppp.assignment_id(+)
and (ppp.change_date is null
     or ppp.change_date = (select max (change_date)
                        from per_pay_proposals pro3
                        where ppp.assignment_id = pro3.assignment_id
                        and pro3.approved = 'Y'))
and pro1.pay_proposal_id = pppc.pay_proposal_id(+)
and sysdate between ppf.effective_start_date and ppf.effective_end_date
and sysdate between psf.effective_start_date and psf.effective_end_date
--
and ppf.employee_number = '1309'
order by
    1,2;