SELECT assa.vendor_id
,asa.vendor_name
,assa.vendor_site_code
,asa.segment1 vendor_number
,assa.vendor_site_id
,assa.address_line1
,assa.address_line2
,assa.city
,assa.state
,assa.zip postal_code
,assa.country
,asa.vat_registration_num
,asa.vendor_type_lookup_code vendor_type
,decode(nvl(assa.hold_unmatched_invoices_flag, 'N'), 'Y', 'PO', 'NONPO') invoice_type
,asa.invoice_currency_code currency_code
,assa.org_id
,hou.name operating_unit
,assa.vendor_site_code
,gcc.segment1 || '.' || gcc.segment2 || '.' || gcc.segment3 || '.' || gcc.segment4 || '.' || gcc.segment5 || '.' || gcc.segment6 liability_account
,apt.name term_name
,ipmb.payment_method_code
FROM fnd_lookup_values lv
,iby_payment_methods_b ipmb
,iby_ext_party_pmt_mthds epm
,hr_organization_units hou
,iby_external_payees_all iepa
,ap_terms apt
,gl_code_combinations gcc
,ap_supplier_sites_all assa
,ap_suppliers asa
WHERE lv.attribute2(+) = 'Y'
AND lv.lookup_code(+) = assa.pay_group_lookup_code
AND ipmb.payment_method_code(+) = epm.payment_method_code
AND NVL(epm.primary_flag, 'Y') = 'Y' -- this is the current/active version. when you make a change, object_version_number changes and old record primary_flag will change to N
AND iepa.supplier_site_id = assa.vendor_site_id
AND epm.ext_pmt_party_id (+) = iepa.ext_payee_id
AND iepa.payee_party_id = asa.party_id
AND apt.term_id = assa.terms_id
AND gcc.code_combination_id = assa.accts_pay_code_combination_id
AND assa.vendor_id = asa.vendor_id
AND assa.org_id = hou.organization_id
-- Supplier and Site Validations
AND nvl(assa.inactive_date, SYSDATE + 1) >= TRUNC(SYSDATE) -- site must be active
AND nvl(asa.end_date_active, SYSDATE + 1) >= TRUNC(SYSDATE) -- supplier must be active
AND asa.vendor_type_lookup_code = 'VENDOR'