SELECT (SELECT NAME
FROM hr_all_organization_units
WHERE organization_id = sups.org_id) operating_unit,
sup.vendor_name, vendor_name_alt alternativ_name,
sup.segment1 vendor_number, vendor_site_code,
vendor_type_lookup_code, sup.end_date_active, address_line1,
sup.creation_date,
(SELECT territory_short_name
FROM fnd_territories_vl
WHERE territory_code = sups.country) country,
q.party_name contact_name, q.phone_number, q.email_address,
q.fax_number, (SELECT NAME
FROM ap_terms_vl
WHERE term_id = sups.terms_id) terms,
sup.attribute1 CATEGORY, sup.attribute2 sub_category,
purchasing_site_flag, pay_site_flag, rfq_only_site_flag,
(SELECT concatenated_segments
FROM gl_code_combinations_kfv
WHERE code_combination_id =
sups.prepay_code_combination_id)
prepay_account,
(SELECT concatenated_segments
FROM gl_code_combinations_kfv
WHERE code_combination_id =
sups.accts_pay_code_combination_id)
liability_account,
(SELECT employee_number
FROM per_all_people_f
WHERE person_id = sup.employee_id
AND SYSDATE BETWEEN effective_start_date
AND effective_end_date) employee_number
FROM ap_suppliers sup,
ap_supplier_sites_all sups,
(SELECT DISTINCT hzr.object_id, hp.party_name,
hcpp.raw_phone_number phone_number,
hcpe.email_address,
hcpf.raw_phone_number fax_number
FROM hz_parties hp,
fnd_user fu,
hz_relationships hzr,
hz_parties hzr_hp,
hz_party_usg_assignments hpua,
hz_contact_points hcpp,
hz_contact_points hcpf,
hz_contact_points hcpe
WHERE hp.party_id = hzr.subject_id
-- AND hzr.object_id = sup.party_id -- party of supplier
AND hzr.relationship_type = 'CONTACT'
AND hzr.relationship_code = 'CONTACT_OF'
AND hzr.subject_type = 'PERSON'
AND hzr.object_type = 'ORGANIZATION'
AND ( hzr.end_date IS NULL
OR hzr.end_date > SYSDATE
)
AND hzr.status = 'A'
AND hzr_hp.party_id = hzr.party_id
AND fu.person_party_id(+) = hp.party_id
AND hpua.party_id = hp.party_id
AND hpua.status_flag = 'A'
AND hpua.party_usage_code = 'SUPPLIER_CONTACT'
AND hcpp.owner_table_name(+) = 'HZ_PARTIES'
AND hcpp.owner_table_id(+) = hzr.party_id
AND hcpp.phone_line_type(+) = 'GEN'
AND hcpp.contact_point_type(+) = 'PHONE'
AND hcpp.primary_flag(+) = 'Y'
AND hcpe.owner_table_name(+) = 'HZ_PARTIES'
AND hcpe.owner_table_id(+) = hzr.party_id
AND hcpe.contact_point_type(+) = 'EMAIL'
AND hcpe.primary_flag(+) = 'Y'
AND hcpe.status(+) = 'A'
AND hcpp.status(+) = 'A'
AND hcpf.owner_table_name(+) = 'HZ_PARTIES'
AND hcpf.owner_table_id(+) = hzr.party_id
AND hcpf.phone_line_type(+) = 'FAX'
AND hcpf.contact_point_type(+) = 'PHONE'
AND hcpf.status(+) = 'A'
AND hcpe.primary_flag(+) = 'N'
AND ( hpua.effective_end_date IS NULL
OR hpua.effective_end_date > SYSDATE
)) q
WHERE sups.vendor_id = sup.vendor_id AND q.object_id(+) =
sup.party_id
ORDER BY sup.vendor_id, 4, 5