You are on page 1of 2

SELECT

pap.full_name,
ood.organization_code "INV_ORG",
(
SELECT
location_code
FROM
hr_locations_all
WHERE
location_id = poh.ship_to_location_id
) po_ship_to_location,
hou.name operating_unit_name,
msib.segment1 as "ITEM_NUMBER",
msib.DESCRIPTION item_description,
poh.segment1 PO_NUMBER,
poh.AUTHORIZATION_STATUS "PO_HEADER_STATUS",
pol.line_num,
poll.closed_code "PO_LINE_STATUS",
COALESCE(
pod.quantity_ordered,
poll.quantity,
pol.quantity
) quantity,
poll.need_by_date,
poll.promised_date,
(
pol.unit_price * (pod.quantity_ordered - pod.quantity_cancelled)
) line_amount,
pov.segment1 SUPPLIER_NUMBER,
pov.vendor_name SUPPLIER_NAME,
fu.USER_NAME CREATE_BY_NAME --CASE WHEN LENGTH(msib.segment1) = 11 AND (SELECT
location_code FROM hr_locations_all WHERE location_id = poh.ship_to_location_id)
LIKE '%F55%' AND INV_ORG = 'F55' THEN 'Beata Leyland' ELSE 'Other' END AS DQ_OWNER
FROM
APPS.PO_HEADERS_ALL poh,
APPS.PO_LINES_ALL pol,
APPS.mtl_system_items_b msib,
APPS.PO_LINE_LOCATIONS_ALL poll,
APPS.PO_DISTRIBUTIONS_ALL pod,
APPS.po_vendors pov,
APPS.po_vendor_sites_All povs,
APPS.hr_locations_all hrls,
APPS.hr_locations_all hrlb,
APPS.po_line_types polt,
org_organization_definitions ood,
HR_OPERATING_UNITS hou,
fnd_user fu,
apps.per_all_people_f pap
WHERE
1 = 1
AND polt.line_type_id = pol.line_type_id
AND poh.agent_id = pap.person_id
AND povs.vendor_site_id = poh.vendor_site_id
AND pov.vendor_id = poh.vendor_id
AND pol.item_id = msib.inventory_item_id
AND msib.organization_id IN (
SELECT
ORGANIZATION_ID
FROM
ORG_ORGANIZATION_DEFINITIONS
WHERE
ORGANIZATION_CODE in ('XXX')
)
AND poh.po_header_id = pol.po_header_id
AND pol.po_line_id = pod.po_line_id
and poh.CREATED_BY = fu.USER_ID
AND poll.line_location_id = pod.line_location_id
AND poh.ship_to_location_id = hrls.location_id
AND poh.bill_to_location_id = hrlb.location_id
AND hou.organization_id = poh.org_id
and hou.organization_id = ood.operating_unit
and ood.organization_code IN ('XXX')
AND poll.CLOSED_CODE = 'OPEN';

You might also like