SELECT vnd.vendor_name, aia.invoice_num, pha.segment1 po_number,
pla.line_num, ah.hold_lookup_code, ah.release_lookup_code,
(nvl((pda.quantity_ordered
- nvl(pda.quantity_cancelled,
0)) *
pll.price_override, 0)) AS ordered_amount,
(pda.amount_billed) AS billed_amount,
(pda.amount_billed - (nvl((pda.quantity_ordered - nvl(pda.quantity_cancelled, 0)) * pll.price_override, 0))) difference,
pda.quantity_ordered, pda.quantity_delivered
FROM
apps.ap_holds_all ah,
apps.po_line_locations_all
pll,
apps.ap_invoices_all
aia,
apps.po_distributions_all
pda,
apps.po_lines_all
pla,
apps.po_headers_all
pha,
apps.ap_suppliers
vnd
WHERE ah.line_location_id = pll.line_location_id
AND
ah.invoice_id = aia.invoice_id
AND
pla.po_line_id = pll.po_line_id
AND
pda.line_location_id = pll.line_location_id
AND
pha.po_header_id = pla.po_header_id
AND
ah.creation_date BETWEEN (SYSDATE - 120) AND SYSDATE
AND
vnd.vendor_id = pha.vendor_id
ORDER BY vendor_name, invoice_num,
pha.segment1, pla.line_num;