select pha.SEGMENT1 "Po Num"
,pha.PO_HEADER_ID "Header Id"
,pla.PO_LINE_ID "Line Id"
,as1.VENDOR_NAME "Supplier"
,ass1.VENDOR_SITE_CODE "Supplier Site"
,hl1.LOCATION_CODE "Ship To Location"
,hl2.LOCATION_CODE "Bill To Location"
,asc1.FIRST_NAME||','||asc1.MIDDLE_NAME||','||asc1.LAST_NAME "Contact Name"
,msib.SEGMENT1 "Item Name"
,pla.QUANTITY*pla.UNIT_PRICE "Line Total"
,(select sum(l.QUANTITY * l.UNIT_PRICE)
from po_headers_all h
,po_lines_all l
where h.PO_HEADER_ID in l.PO_HEADER_ID
and h.PO_HEADER_ID=pha.PO_HEADER_ID
group by h.PO_HEADER_ID) "Po Total"
from po_headers_all pha
,po_lines_all pla
,ap_suppliers as1
,ap_supplier_sites_all ass1
,hr_locations hl1
,hr_locations hl2
,ap_supplier_contacts asc1
,mtl_system_items_b msib
where 1=1
and msib.INVENTORY_ITEM_ID =:p_item_id
and pha.TYPE_LOOKUP_CODE not in('QUOTATION','RFQ')
and pha.ORG_ID=204
and pha.PO_HEADER_ID=pla.PO_HEADER_ID
and pha.VENDOR_ID=as1.VENDOR_ID
and pha.VENDOR_SITE_ID=ass1.VENDOR_SITE_ID
and pha.SHIP_TO_LOCATION_ID=hl1.LOCATION_ID
and pha.BILL_TO_LOCATION_ID=hl2.LOCATION_ID
and pha.VENDOR_CONTACT_ID=asc1.VENDOR_CONTACT_ID
and pla.ITEM_ID=msib.INVENTORY_ITEM_ID
and msib.ORGANIZATION_ID=204
group by pha.SEGMENT1
,pha.PO_HEADER_ID
,pla.PO_LINE_ID
,as1.VENDOR_NAME
,ass1.VENDOR_SITE_CODE
,hl1.LOCATION_CODE
,hl2.LOCATION_CODE
,asc1.FIRST_NAME||','||asc1.MIDDLE_NAME||','||asc1.LAST_NAME
,pla.QUANTITY*pla.UNIT_PRICE
,msib.SEGMENT1;
No comments:
Post a Comment