SELECT dh.source_order_number
,df.source_line_number as so_line_number
,df.fulfill_line_number
,ddr.doc_user_key as po_number
,ai.invoice_num
,ail.quantity_invoiced
,ail.amount
,ail.line_number as ap_invoice_line_number
FROM fusion.ap_invoices_all ai
,fusion.ap_invoice_lines_all ail
,fusion.doo_document_references ddr
,fusion.doo_headers_all dh
,fusion.doo_fulfill_lines_all df
WHERE ai.invoice_id = ail.invoice_id
AND dh.source_order_number = <sales_order_number>
AND ddr.doc_id = TO_CHAR(ai.po_header_id)
AND ddr.fulfill_line_id = df.fulfill_line_id
AND df.header_id = dh.header_id