AP Query
AP Query
hou.name operating_unit,
--aia.INVOICE_TYPE_LOOKUP_CODE invoice_type,
ALC1.DISPLAYED_FIELD INVOICE_TYPE,
pha.segment1 po_number,
aps.vendor_name ,-- 'Trading_Partner_Name',
aps.segment1 vendor_number,
apss.vendor_site_code,
aia.invoice_date,
aia.invoice_num,
aia.invoice_currency_code,
aia.invoice_amount,
aia.gl_date,
apt.name Term_name,
aia.terms_date,
aia.PAYMENT_METHOD_CODE payment_method,
aia.PAY_GROUP_LOOKUP_CODE Pay_group,
--decode(aida.MATCH_STATUS_FLAG,'A','Validated','N','Never
validated','T','Tested','S','Stoped',NULL,'Never validated')
Invoice_validation_status,
--(select sum(aipa.amount) from ap_invoice_payments_all aipa where aipa.invoice_id
= aia.invoice_id) payment_amount,
ALC2.DISPLAYED_FIELD PAYMENT_STATUS,
aia.amount_paid,
aia.cancelled_amount,
--apsa.amount_remaining,
---DECODE(aia.PAYMENT_STATUS_FLAG,'N','UN-PAID','P','Partial Paid','Y','PAID')
PAYMENT_STATUS_FLAG,
org.location_code,
org.ORGANIZATION_CODE,
AP_INVOICES_PKG.GET_APPROVAL_STATUS( AIA.INVOICE_ID,
AIA.INVOICE_AMOUNT, AIA.PAYMENT_STATUS_FLAG,
AIA.INVOICE_TYPE_LOOKUP_CODE) wf_status
from apps.ap_invoices_all aia,
--ap_invoice_lines_all aila,
--ap_invoice_distributions_all aida,
ap_suppliers aps,
ap_supplier_sites_all apss,
po_headers_all pha,
ap_terms apt,
hr_operating_units hou,
(select
hl.location_id,
mp.ORGANIZATION_CODE,
hl.location_code
from hr_locations hl
, mtl_parameters mp
, fnd_lookup_values_vl flv
where hl.inventory_organization_id = mp.organization_id
--and hl.location_id = 213
and flv.lookup_code = mp.organization_code
and flv.lookup_type = 'ACCO_INV_ORGS'
and flv.enabled_flag = 'Y'
and nvl(flv.end_date_active,trunc(sysdate)) >= trunc(sysdate)
order by 1) org,
AP_LOOKUP_CODES ALC1,
AP_LOOKUP_CODES ALC2
where 1=1
---AND AIA.INVOICE_NUM in ('DS-20210503B','ACCO UK INVENTORY 04.02.2021UK')
--and aia.PAYMENT_STATUS_FLAG <>'Y'
---and aia.invoice_id = aila.invoice_id
--and aila.invoice_id = aida.invoice_id
--and aila.line_number = aida.invoice_line_number
--AND AIDA.CANCELLATION_FLAG = 'N'
and aia.vendor_id=aps.vendor_id
and aia.VENDOR_SITE_ID=APSS.VENDOR_SITE_ID
AND aps.vendor_id=apss.VENDOR_ID
and aia.quick_po_header_id=pha.po_header_id(+)
and apt.term_id=aia.terms_id
and hou.organization_id=aia.org_id
and pha.ship_to_location_id =org.location_id(+)
AND ALC1.LOOKUP_TYPE (+) = 'INVOICE TYPE'
AND ALC1.LOOKUP_CODE (+) = AIA.INVOICE_TYPE_LOOKUP_CODE
AND ALC2.LOOKUP_TYPE (+) = 'INVOICE PAYMENT STATUS'
AND ALC2.LOOKUP_CODE (+) = AIA.PAYMENT_STATUS_FLAG
and (aps.vendor_name like 'ACCO %' or aps.segment1 like 'ACCO %' OR
aia.PAYMENT_METHOD_CODE like 'ACCO %')
order by aia.invoice_num