Query
Query
distinct decode(pha.org_id,
'240','SPS_GC_545L','3237','SPS_GC_545L','241','SPS_GC_588L','2638','SPS_GC_988L','
2757','SPS_GC_988L','2817','SPS_GC_988L','2917','SPS_GC_988L','3157','SPS_GC_988L',
'3337','SPS_GC_722L','3278','SPS_GC_982L') Organization_name,
pha.org_id org_id,
pda.destination_organization_id,
pha.type_lookup_code,
pha.segment1 PO_NUMBER,
pla.line_num PO_LINE_NUMBER,
plla.shipment_num Shipment_Number,
'' Release_Number,
PV.SEGMENT1 VENDOR_NUMBER,
pv.vendor_name,
pvsa.VENDOR_SITE_ID VENDOR_SITE_ID,
pvsa.vendor_site_code,
pha.creation_date,
(SELECT name
FROM apps.ap_terms_tl
WHERE term_id = pha.terms_id
AND language = 'US') pay_term,
pha.currency_code,
(select distinct full_name
FROM apps.PER_ALL_PEOPLE_F PAPF
WHERE PAPF.PERSON_ID = pha.AGENT_ID) buyer,
(select UPPER(line_type)
from apps.po_line_types_tl
where language = 'US'
and line_type_id = pla.line_type_id) po_line_type,
(select segment1
from apps.mtl_system_items_b
where inventory_item_id = pla.item_id
and organization_id = pda.destination_organization_id) material,
pla.item_description item_description,
NVL(plla.consigned_flag, 'N') Consigned_PO_line,
decode(nvl((SELECT msib.Consigned_Flag
FROM apps.MTL_SYSTEM_ITEMS_B MSIB
WHERE msib.inventory_item_id = pla.item_id
AND MSIb.ORGANIZATION_ID =
pda.destination_organization_id),
2),
'1',
'Y',
'N') Consigned_material,
(select outside_operation_flag
from apps.mtl_system_items_b
where inventory_item_id = pla.item_id
and organization_id = pda.destination_organization_id) OSP_material,
gcc1.segment1 entity,
gcc1.segment2 gl_account,
gcc1.segment3 sub_account,
gcc1.segment4 department,
gcc1.segment5 LOB,
gcc1.segment6 VM,
gcc1.segment7 location,
plla.need_by_date need_by_date,
plla.promised_date promised_date,
(plla.quantity - plla.quantity_received - plla.quantity_cancelled)
due_QUANTITY,
pla.unit_meas_lookup_code PO_UNIT,
pla.unit_price,
case
when gcc1.segment2 LIKE '116%' and
(select UPPER(line_type)
from apps.po_line_types_tl
where language = 'US'
and line_type_id = pla.line_type_id) not like '%OSP%' then
'Direct_PO'
when gcc1.segment2 like '143%' then
'Fixed_Asset_PO'
else
'Indirect_PO'
end PO_Type,
case
when gcc1.segment2 LIKE '116%' and
(select UPPER(line_type)
from apps.po_line_types_tl
where language = 'US'
and line_type_id = pla.line_type_id) not like '%OSP%' then
'A300'
when gcc1.segment2 like '143%' then
'A200'
else
'A200'
end Purch_Org,
case
when gcc1.segment2 LIKE '116%' and
(select UPPER(line_type)
from apps.po_line_types_tl
where language = 'US'
and line_type_id = pla.line_type_id) not like '%OSP%' then
null
when gcc1.segment2 like '143%' then
'N'
else
'K'
end Account_Assignment,
(select gcc.segment5 lob
from fnd_flex_value_sets ffvs2,
fnd_flex_values_vl ffv2,
gl_code_combinations gcc
where ffvs2.flex_value_set_name = upper('HW_LOB')
and ffvs2.flex_value_set_id = ffv2.flex_value_set_id
and ffv2.flex_value = gcc.segment5
and pda.accrual_account_id = gcc.code_combination_id)
accrual_account_lob,
(select gcc.segment5 lob
from fnd_flex_value_sets ffvs2,
fnd_flex_values_vl ffv2,
gl_code_combinations gcc
where ffvs2.flex_value_set_name = upper('HW_LOB')
and ffvs2.flex_value_set_id = ffv2.flex_value_set_id
and ffv2.flex_value = gcc.segment5
and pda.variance_account_id = gcc.code_combination_id)
variance_account_lob,
(select gcc.segment5 lob
from fnd_flex_value_sets ffvs2,
fnd_flex_values_vl ffv2,
gl_code_combinations gcc,
apps.mtl_system_items_b msib
where ffvs2.flex_value_set_name = upper('HW_LOB')
and ffvs2.flex_value_set_id = ffv2.flex_value_set_id
and ffv2.flex_value = gcc.segment5
and msib.cost_of_sales_account = gcc.code_combination_id
and msib.inventory_item_id = pla.item_id
and msib.organization_id = pda.destination_organization_id)
MATERIAL_lob
FROM apps.po_headers_all pha,
apps.po_lines_all pla,
apps.po_line_locations_all plla,
apps.po_vendors pv,
apps.po_vendor_sites_all pvsa,
apps.po_distributions_all pda,
apps.gl_code_combinations gcc1
WHERE pha.po_header_id = pla.po_header_id
and pha.po_header_id = plla.po_header_id
AND pla.po_line_id = plla.po_line_id
AND pha.vendor_id = pv.vendor_id
and pha.vendor_site_id = pvsa.vendor_site_id
AND pv.vendor_id = pvsa.vendor_id
AND pla.po_line_id = pda.po_line_id
AND pla.org_id = pda.org_id
AND pda.code_combination_id = gcc1.code_combination_id
AND NVL(pha.closed_Code, 'OPEN') = 'OPEN'
AND NVL(pla.closed_Code, 'OPEN') = 'OPEN'
AND NVL(plla.closed_code, 'OPEN') NOT LIKE '%CLOSED%'
AND upper(pha.authorization_status) = 'APPROVED'
AND (plla.quantity - plla.quantity_received - plla.quantity_cancelled) > 0
AND (NVL(pha.cancel_flag, 'N') <> 'Y' OR
NVL(pla.cancel_flag, 'N') <> 'Y' OR
NVL(plla.cancel_flag, 'N') <> 'Y')
and upper(pha.type_lookup_code) = 'STANDARD'
--and pha.segment1='8029282'
and pha.org_id in (240,3237,241,2638,2757,2817,2917,3157,3337,3278)
and rownum <= 10;