Select AIA. invoice_num,
AIA. invoice_date,
AIA. creation_date,
AIA. vendor_id,
AIA. invoice_currency_code,
AIl. amount,
AIl. base_amount,
AIA. description,
Decode (AIL. base_amount,
Null,
1,
Round (AIL. base_amount/ail. amount, 4 )),
AIl. inventory_item_id,
AIl. quantity_invoiced,
AIl. unit_price,
AIl. amount,
AIl. base_amount,
AIl. rcv_transaction_id,
MSI. segment1,
MSI. description,
RSH. receipt_num,
PHA. segment1,
PV. vendor_name,
RSL. quantity_policed
From AP. ap_invoices_all AIA,
AP. ap_invoice_lines_all aIl,
Po. po_headers_all PHA,
Apps. po_vendors PV,
Inv. mtl_system_items_ B MSI,
Rcv_shipment_headers RSH, -- receiving Header
Rcv_shipment_lines RSL -- receiving line
Where AIA. invoice_id = ail. invoice_id
And ail. po_header_id = PHA. po_header_id (+)
And AIA. vendor_id = pv. vendor_id
And ail. inventory_item_id = MSI. inventory_item_id (+)
And ail.org _ id = MSI. organization_id (+)
And ail. rcv_shipment_line_id = RSL. shipment_line_id (+)
And RSL. shipment_header_id = RSH. shipment_header_id (+)
And ail. line_type_lookup_code = 'item'