SELECT ap.segment1 vendor_code,
ap.vendor_name Suppliers_Name,
aps.vendor_site_code Supplier_Site_Code,
ap.VENDOR_TYPE_LOOKUP_CODE Type_Code,
aps.address_line1,
aps.address_line2,
aps.address_line3,
aps.city,
aps.state,
aps.zip,
aps.Country,
apc.AREA_CODE,
apc.PHONE,
apc.FAX_AREA_CODE,
apc.FAX,
apc.EMAIL_ADDRESS,
ap.PAYMENT_CURRENCY_CODE CURRENCY_CODE,
(Select Name from hr_operating_units where organization_id=aps.ORG_ID) OU_NAME,
aps.vat_registration_num,
aps.auto_tax_calc_flag,
ap.offset_tax_flag offset_tax_flag_header,
aps.offset_tax_flag offset_tax_flag_line,
aps.attribute2 free_field,
(Select LOCATION_CODE from hr_locations where location_id= aps.ship_to_location_id) ship_location,
(Select LOCATION_CODE from hr_locations where location_id= aps.bill_to_location_id) bill_location,
(SELECT terms.NAME
From ap_terms_tl terms
WHERE terms.term_id = ap.terms_id
AND terms.LANGUAGE(+) = USERENV ('LANG')
AND terms.enabled_flag(+) = 'Y')AS terms_header,
(SELECT terms.NAME
From ap_terms_tl terms
WHERE terms.term_id = aps.terms_id
AND terms.LANGUAGE(+) = USERENV ('LANG')
AND terms.enabled_flag(+) = 'Y')AS terms_line,
ap.attribute9 supplier_category,
(SELECT concatenated_segments FROM gl_code_combinations_kfv WHERE code_combination_id=aps.ACCTS_PAY_CODE_COMBINATION_ID) ACCTS_AC,
(SELECT concatenated_segments FROM gl_code_combinations_kfv WHERE code_combination_id=aps.PREPAY_CODE_COMBINATION_ID) PRPAY_AC
FROM ap_suppliers ap,
ap_supplier_sites_all aps,
ap_supplier_contacts apc
WHERE ap.vendor_id = aps.vendor_id
AND apc.VENDOR_CONTACT_ID(+) = ap.VENDOR_ID
AND ap.VENDOR_TYPE_LOOKUP_CODE <> 'EMPLOYEE'
AND aps.vendor_site_code NOT IN 'OFFICE'
AND ap.enabled_flag ='Y'
--AND ap.segment1='19173'
ORDER BY ap.vendor_name,ap.segment1
ap.vendor_name Suppliers_Name,
aps.vendor_site_code Supplier_Site_Code,
ap.VENDOR_TYPE_LOOKUP_CODE Type_Code,
aps.address_line1,
aps.address_line2,
aps.address_line3,
aps.city,
aps.state,
aps.zip,
aps.Country,
apc.AREA_CODE,
apc.PHONE,
apc.FAX_AREA_CODE,
apc.FAX,
apc.EMAIL_ADDRESS,
ap.PAYMENT_CURRENCY_CODE CURRENCY_CODE,
(Select Name from hr_operating_units where organization_id=aps.ORG_ID) OU_NAME,
aps.vat_registration_num,
aps.auto_tax_calc_flag,
ap.offset_tax_flag offset_tax_flag_header,
aps.offset_tax_flag offset_tax_flag_line,
aps.attribute2 free_field,
(Select LOCATION_CODE from hr_locations where location_id= aps.ship_to_location_id) ship_location,
(Select LOCATION_CODE from hr_locations where location_id= aps.bill_to_location_id) bill_location,
(SELECT terms.NAME
From ap_terms_tl terms
WHERE terms.term_id = ap.terms_id
AND terms.LANGUAGE(+) = USERENV ('LANG')
AND terms.enabled_flag(+) = 'Y')AS terms_header,
(SELECT terms.NAME
From ap_terms_tl terms
WHERE terms.term_id = aps.terms_id
AND terms.LANGUAGE(+) = USERENV ('LANG')
AND terms.enabled_flag(+) = 'Y')AS terms_line,
ap.attribute9 supplier_category,
(SELECT concatenated_segments FROM gl_code_combinations_kfv WHERE code_combination_id=aps.ACCTS_PAY_CODE_COMBINATION_ID) ACCTS_AC,
(SELECT concatenated_segments FROM gl_code_combinations_kfv WHERE code_combination_id=aps.PREPAY_CODE_COMBINATION_ID) PRPAY_AC
FROM ap_suppliers ap,
ap_supplier_sites_all aps,
ap_supplier_contacts apc
WHERE ap.vendor_id = aps.vendor_id
AND apc.VENDOR_CONTACT_ID(+) = ap.VENDOR_ID
AND ap.VENDOR_TYPE_LOOKUP_CODE <> 'EMPLOYEE'
AND aps.vendor_site_code NOT IN 'OFFICE'
AND ap.enabled_flag ='Y'
--AND ap.segment1='19173'
ORDER BY ap.vendor_name,ap.segment1