SELECT operating_unit, receiving_organization, po_number, po_creation_date,
vendor_code, vendor_name, material_code, material_description,
need_by_date po_need_by_date, unit_price, po_qty,
po_qty * unit_price po_line_price, received_qty,
received_qty * unit_price receivied_qty_price, accepted_qty,
rejected_qty, balance_qty_to_be_received,
balance_qty_to_be_received * unit_price balance_qty_price
FROM (SELECT ou.NAME operating_unit,
ood.organization_name receiving_organization,
pha.segment1 po_number,
pha.creation_date "PO_CREATION_DATE",
aps.segment1 "VENDOR_CODE", aps.vendor_name,
msib.segment1 "MATERIAL_CODE",
msib.description "MATERIAL_DESCRIPTION", plla.need_by_date,
pla.unit_price, pla.unit_meas_lookup_code "UOM",
plla.quantity "PO_QTY",
SUM (plla.quantity_received) "RECEIVED_QTY",
SUM (plla.quantity_accepted) "ACCEPTED_QTY",
SUM (plla.quantity_rejected) "REJECTED_QTY",
(plla.quantity - plla.quantity_received
) "BALANCE_QTY_TO_BE_RECEIVED"
FROM apps.po_headers_all pha,
apps.po_lines_all pla,
apps.po_line_locations_all plla,
apps.po_distributions_all pda,
apps.mtl_system_items_b msib,
apps.ap_suppliers aps,
apps.org_organization_definitions ood,
apps.hr_operating_units ou
WHERE pha.vendor_id = aps.vendor_id
AND pha.po_header_id = pla.po_header_id
AND pla.po_line_id = plla.po_line_id
AND pla.po_header_id = plla.po_header_id
AND pla.item_id = msib.inventory_item_id
AND pda.destination_organization_id = msib.organization_id
AND (pha.creation_date) <= '01-JAN-2016'
AND NVL (pla.closed_code, 'OPEN') NOT IN
('CLOSED', 'FINALLY CLOSED')
AND NVL (pha.closed_code, 'OPEN') NOT IN
('CLOSED', 'FINALLY CLOSED')
AND NVL (pha.cancel_flag, 'N') = 'N'
AND NVL (pla.cancel_flag, 'N') = 'N'
AND pha.closed_date IS NULL
AND pha.org_id IN (1792, 1793, 1042, 1043, 1044, 1041)
AND ood.organization_id = pda.destination_organization_id
AND plla.line_location_id = pda.line_location_id
AND plla.po_line_id = pda.po_line_id
AND plla.po_header_id = pda.po_header_id
AND ou.organization_id = pha.org_id
--and pha.segment1 = '1'
GROUP BY pha.segment1,
pha.creation_date,
aps.segment1,
msib.segment1,
msib.description,
plla.quantity,
plla.need_by_date,
pla.unit_meas_lookup_code,
plla.quantity,
plla.quantity_received,
plla.quantity_accepted,
plla.quantity_rejected,
plla.quantity,
plla.quantity_received,
ood.organization_name,
aps.vendor_name,
pla.unit_price,
ou.NAME) tab
WHERE balance_qty_to_be_received > 0
ORDER BY 1, 2, 3 ASC;
vendor_code, vendor_name, material_code, material_description,
need_by_date po_need_by_date, unit_price, po_qty,
po_qty * unit_price po_line_price, received_qty,
received_qty * unit_price receivied_qty_price, accepted_qty,
rejected_qty, balance_qty_to_be_received,
balance_qty_to_be_received * unit_price balance_qty_price
FROM (SELECT ou.NAME operating_unit,
ood.organization_name receiving_organization,
pha.segment1 po_number,
pha.creation_date "PO_CREATION_DATE",
aps.segment1 "VENDOR_CODE", aps.vendor_name,
msib.segment1 "MATERIAL_CODE",
msib.description "MATERIAL_DESCRIPTION", plla.need_by_date,
pla.unit_price, pla.unit_meas_lookup_code "UOM",
plla.quantity "PO_QTY",
SUM (plla.quantity_received) "RECEIVED_QTY",
SUM (plla.quantity_accepted) "ACCEPTED_QTY",
SUM (plla.quantity_rejected) "REJECTED_QTY",
(plla.quantity - plla.quantity_received
) "BALANCE_QTY_TO_BE_RECEIVED"
FROM apps.po_headers_all pha,
apps.po_lines_all pla,
apps.po_line_locations_all plla,
apps.po_distributions_all pda,
apps.mtl_system_items_b msib,
apps.ap_suppliers aps,
apps.org_organization_definitions ood,
apps.hr_operating_units ou
WHERE pha.vendor_id = aps.vendor_id
AND pha.po_header_id = pla.po_header_id
AND pla.po_line_id = plla.po_line_id
AND pla.po_header_id = plla.po_header_id
AND pla.item_id = msib.inventory_item_id
AND pda.destination_organization_id = msib.organization_id
AND (pha.creation_date) <= '01-JAN-2016'
AND NVL (pla.closed_code, 'OPEN') NOT IN
('CLOSED', 'FINALLY CLOSED')
AND NVL (pha.closed_code, 'OPEN') NOT IN
('CLOSED', 'FINALLY CLOSED')
AND NVL (pha.cancel_flag, 'N') = 'N'
AND NVL (pla.cancel_flag, 'N') = 'N'
AND pha.closed_date IS NULL
AND pha.org_id IN (1792, 1793, 1042, 1043, 1044, 1041)
AND ood.organization_id = pda.destination_organization_id
AND plla.line_location_id = pda.line_location_id
AND plla.po_line_id = pda.po_line_id
AND plla.po_header_id = pda.po_header_id
AND ou.organization_id = pha.org_id
--and pha.segment1 = '1'
GROUP BY pha.segment1,
pha.creation_date,
aps.segment1,
msib.segment1,
msib.description,
plla.quantity,
plla.need_by_date,
pla.unit_meas_lookup_code,
plla.quantity,
plla.quantity_received,
plla.quantity_accepted,
plla.quantity_rejected,
plla.quantity,
plla.quantity_received,
ood.organization_name,
aps.vendor_name,
pla.unit_price,
ou.NAME) tab
WHERE balance_qty_to_be_received > 0
ORDER BY 1, 2, 3 ASC;
No comments:
Post a Comment