SELECT mmt.transaction_date
,(SELECT ml.meaning
FROM mfg_lookups ml
WHERE ml.lookup_Type = 'CST_ACCOUNTING_LINE_TYPE'
AND ml.lookup_code = mta.accounting_line_type
) accounting_type
,gl_code.concatenated_segments account, mtt.transaction_type_name transaction_type
,(SELECT po_hdr.segment1
FROM po_headers_all po_hdr
WHERE po_hdr.po_header_id = po_dist.po_header_id) transaction_source
,mmt.transaction_uom uom
,mta.primary_quantity
,mta.base_transaction_value
,mmt.transaction_id, mmt.transaction_type_id, items.segment1 item, mmt.inventory_item_id, mmt.organization_id
,gl_code.code_combination_id
FROM ap_invoice_distributions_all inv_dist
,po_distributions_all po_dist
,rcv_transactions rcv_trx
,mtl_material_transactions mmt
,mtl_transaction_types mtt
,mtl_transaction_accounts mta
,gl_code_combinations_kfv gl_code
,mtl_system_items_b items
WHERE 1=1
--AND inv_dist.po_distribution_id = 10536072
AND inv_dist.po_distribution_id = po_dist.po_distribution_id
AND po_dist.po_header_id = rcv_trx.po_header_id
AND po_dist.po_line_id = rcv_trx.po_line_id
AND po_dist.line_location_id = rcv_trx.po_line_location_id
AND po_dist.po_distribution_id = rcv_trx.po_distribution_id
AND transaction_type = 'DELIVER'
AND mmt.rcv_transaction_id = rcv_trx.transaction_id
AND mmt.transaction_type_id = mtt.transaction_type_id
AND mmt.transaction_id = mta.transaction_id
AND mta.reference_account = gl_code.code_combination_id
AND mmt.inventory_item_id = items.inventory_item_id
AND mmt.organization_id = items.organization_id