SELECT PVS.VENDOR_SITE_CODE VENDOR_SITE_CODE
, PVS.VENDOR_SITE_ID VENDOR_SITE_ID, PVS.VENDOR_ID VENDOR_ID
, PVS.ADDRESS_LINE1 ADDRESS_LINE1
, PVS.ADDRESS_LINE2 ADDRESS_LINE2
, PVS.ADDRESS_LINE3 ADDRESS_LINE3
, PVS.ADDRESS_LINE4 ADDRESS_LINE4
, PVS.ADDRESS_STYLE ADDRESS_STYLE
, PVS.CITY CITY
, PVS.COUNTY COUNTY
, PVS.STATE STATE
, PVS.PROVINCE PROVINCE
, PVS.ZIP ZIP
, PVS.COUNTRY COUNTRY
, PVS.INVOICE_CURRENCY_CODE INVOICE_CURRENCY_CODE
, PVS.TERMS_ID TERMS_ID
, AT.NAME TERMS_NAME
, PVS.PAY_GROUP_LOOKUP_CODE PAY_GROUP_LOOKUP_CODE
, PVS.TERMS_DATE_BASIS TERMS_DATE_BASIS
, ALC2.DISPLAYED_FIELD TERMS_DATE_BASIS_DISP
, PVS.ACCTS_PAY_CODE_COMBINATION_ID ACCTS_PAY_CODE_COMBINATION_ID
, PVS.INVOICE_AMOUNT_LIMIT INVOICE_AMOUNT_LIMIT
, PVS.DISTRIBUTION_SET_ID DISTRIBUTION_SET_ID
, ADS.DISTRIBUTION_SET_NAME DISTRIBUTION_SET_NAME
, PVS.PAYMENT_PRIORITY PAYMENT_PRIORITY
, PVS.PAY_DATE_BASIS_LOOKUP_CODE PAY_DATE_BASIS_LOOKUP_CODE
, PVS.HOLD_FUTURE_PAYMENTS_FLAG HOLD_FUTURE_PAYMENTS_FLAG
, PVS.EXCLUDE_FREIGHT_FROM_DISCOUNT EXCLUDE_FREIGHT_FROM_DISCOUNT
, PVS.ALLOW_AWT_FLAG ALLOW_AWT_FLAG
, PVS.AWT_GROUP_ID AWT_GROUP_ID
, AWT.NAME AWT_GROUP_NAME
, FT.TERRITORY_SHORT_NAME TERRITORY_SHORT_NAME
, DECODE(SIGN(TO_DATE(TO_CHAR(PVS.INACTIVE_DATE
, 'YYYY/MM/DD')
, 'YYYY/MM/DD') - TO_DATE(TO_CHAR(SYSDATE
, 'YYYY/MM/DD')
, 'YYYY/MM/DD'))
, -1
, 'N'
, 0
, 'N'
, 'Y') ACTIVE_FLAG
, PVS.HOLD_ALL_PAYMENTS_FLAG HOLD_ALL_PAYMENTS_FLAG
, PVS.ALWAYS_TAKE_DISC_FLAG ALWAYS_TAKE_DISC_FLAG
, PVS.PAYMENT_CURRENCY_CODE PAYMENT_CURRENCY_CODE
, PVS.ORG_ID
, PVS.PARTY_SITE_ID
, IEP.PAYEE_PARTY_ID
, IEP.PAYMENT_FUNCTION
, IEP.BANK_CHARGE_BEARER
, IEP.SETTLEMENT_PRIORITY
, IEP.EXCLUSIVE_PAYMENT_FLAG
, PVS.PREPAY_CODE_COMBINATION_ID
, PVS.PAY_AWT_GROUP_ID PAY_AWT_GROUP_ID
, AWT1.NAME PAY_AWT_GROUP_NAME
FROM AP_SUPPLIER_SITES PVS
, AP_SUPPLIERS PV
, IBY_EXTERNAL_PAYEES_ALL IEP
, FND_TERRITORIES_VL FT
, AP_TERMS AT
, AP_LOOKUP_CODES ALC2
, AP_DISTRIBUTION_SETS_ALL ADS
, AP_AWT_GROUPS AWT
, AP_AWT_GROUPS AWT1
WHERE PVS.COUNTRY = FT.TERRITORY_CODE (+)
AND AT.TERM_ID (+) = PVS.TERMS_ID
AND ALC2.LOOKUP_CODE (+) = PVS.TERMS_DATE_BASIS
AND ALC2.LOOKUP_TYPE (+) = 'TERMS DATE BASIS'
AND AWT.GROUP_ID (+) = PVS.AWT_GROUP_ID
AND ADS.DISTRIBUTION_SET_ID (+) = PVS.DISTRIBUTION_SET_ID
AND PVS.PAY_SITE_FLAG = 'Y'
AND PVS.VENDOR_ID = PV.VENDOR_ID
AND PV.PARTY_ID = IEP.PAYEE_PARTY_ID
AND PVS.VENDOR_SITE_ID = IEP.SUPPLIER_SITE_ID(+)
AND AWT1.GROUP_ID(+)=PVS.PAY_AWT_GROUP_ID