Select
E.full_name Buyer,
SUM (plla.quantity-plla.quantity_cancelled) Order quantity,
Sum (Plla. quantity_received) to complete the quantity,
Round (SUM (Plla). quantity_received) *100/sum (plla.quantity-plla.quantity_cancelled), 2) | | % ' percent complete
From
PO. Po_agents PA,
PO. Po_headers_all PHA,
PO. Po_lines_all PLA,
PO. Po_line_locations_all Plla,
PO. Po_vendors PV,
hr. Per_all_people_f E,
Inv.mtl_system_items_b MSI
where
pha.org_id = X
and (PHA. po_header_id = pla. PO_HEADER_ID)
and (PLA. Po_line_id=plla. PO_LINE_ID)
and (PHA. Agent_id=pa. AGENT_ID)
and (pha.org_id=pla.org_id)
and (msi.inventory_item_id = pla.item_id)
and (msi.organization_id in (x, y))
and (msi.organization_id = plla.ship_to_organization_id)
and (PHA. VENDOR_ID=PV. VENDOR_ID)
and (pha.agent_id=e.person_id (+)))
and NVL (PHA. Approved_flag, ' N ') = ' Y '
and NVL (Plla. Approved_flag, ' N ') = ' Y '
and NVL (PHA. Cancel_flag, ' n ') = ' n '
and NVL (PLA. Cancel_flag, ' n ') = ' n '
and NVL (Plla. Cancel_flag, ' n ') = ' n '
and Pha.type_lookup_code = ' standard '
and NVL (plla.need_by_date,plla.promised_date) between
To_date (' 20**-01-01 ', ' yyyy-mm-dd ') and to_date (' 20**-01-31 ', ' yyyy-mm-dd ')
GROUP BY
E.full_name