Anda di halaman 1dari 3

SELECT segment1

,inv_item_id item_id
,mk_by
,ord_type
,dt_ord
,dem_dt
,qty
,sr_name
,vendor_id
,vendor_site_id
,using_assembly_demand_date
,organizationid
, (SELECT RTRIM (XMLAGG (XMLELEMENT (e, segment1 || '~~')).EXTRACT
('//text()'), '~~')
FROM po_headers_all pha
,po_lines_all pla
,po_ga_org_assignments pgoa
WHERE 1 = 1
AND pha.po_header_id = pla.po_header_id
AND pha.global_agreement_flag = 'Y'
AND pha.authorization_status = 'APPROVED'
AND NVL (pha.closed_code, 'OPEN') = 'OPEN'
AND NVL (pla.cancel_flag, 'X') != 'Y'
AND pha.type_lookup_code = 'BLANKET'
AND TRUNC (SYSDATE) BETWEEN NVL (pha.start_date, TRUNC
(pha.creation_date)) AND NVL (pha.end_date, TRUNC (SYSDATE))
AND pgoa.po_header_id = pha.po_header_id
AND NVL (pgoa.enabled_flag, 'N') = 'Y'
AND pla.item_id = inv_item_id
--inv_item_id
AND TO_CHAR (pgoa.purchasing_org_id) IN DECODE (:p_organization_id
,854, 834
,855, 835
,NVL
(:p_organization_id, pgoa.organization_id))) gpa_number
FROM (SELECT msi.segment1
,mgr.inventory_item_id inv_item_id
,DECODE (msi.planning_make_buy_code
,1, 'Make'
,2, 'Buy') mk_by
,'Gross Requirement' ord_type
,using_assembly_demand_date
,TO_CHAR (using_assembly_demand_date, 'RRRRMMDD') dt_ord
,TO_CHAR (using_assembly_demand_date, 'MM/DD/RRRR') dem_dt
,SUM (using_requirements_quantity) qty
, (SELECT msr.sourcing_rule_name
FROM mrp_sr_assignments msa
,mrp_sourcing_rules msr
,mrp_sr_receipt_org msro
,mrp_sr_source_org msso
WHERE 1 = 1
AND msa.sourcing_rule_id = msr.sourcing_rule_id
AND msr.sourcing_rule_id = msro.sourcing_rule_id
AND msro.sr_receipt_id = msso.sr_receipt_id
AND msso.allocation_percent = 100
AND TRUNC (SYSDATE) BETWEEN TRUNC (NVL
(msro.effective_date, SYSDATE)) AND TRUNC (NVL (msro.disable_date, SYSDATE))
AND msa.assignment_set_id = 2
AND assignment_type IN (6, 3)
AND msa.inventory_item_id = msi.inventory_item_id
AND msa.organization_id = msi.organization_id) sr_name
, (SELECT msi.organization_id
FROM mrp_sr_assignments msa
,mrp_sourcing_rules msr
,mrp_sr_receipt_org msro
,mrp_sr_source_org msso
WHERE 1 = 1
AND msa.sourcing_rule_id = msr.sourcing_rule_id
AND msr.sourcing_rule_id = msro.sourcing_rule_id
AND msro.sr_receipt_id = msso.sr_receipt_id
AND msso.allocation_percent = 100
AND TRUNC (SYSDATE) BETWEEN TRUNC (NVL
(msro.effective_date, SYSDATE)) AND TRUNC (NVL (msro.disable_date, SYSDATE))
AND msa.assignment_set_id = 2
AND assignment_type IN (6, 3)
AND msa.inventory_item_id = msi.inventory_item_id
AND msa.organization_id = msi.organization_id)
organizationid
, (SELECT pv.vendor_id
--segment1--pv.vendor_name
FROM mrp_sr_assignments msa
,mrp_sourcing_rules msr
,mrp_sr_receipt_org msro
,mrp_sr_source_org msso
,po_vendors pv
WHERE 1 = 1
AND msa.sourcing_rule_id = msr.sourcing_rule_id
AND msr.sourcing_rule_id = msro.sourcing_rule_id
AND msro.sr_receipt_id = msso.sr_receipt_id
AND msso.allocation_percent = 100
AND TRUNC (SYSDATE) BETWEEN TRUNC (NVL
(msro.effective_date, SYSDATE)) AND TRUNC (NVL (msro.disable_date, SYSDATE))
AND msso.vendor_id = pv.vendor_id
AND msa.assignment_set_id = 2
AND assignment_type IN (6, 3)
AND msa.inventory_item_id = msi.inventory_item_id
AND msa.organization_id = msi.organization_id) vendor_id
, (SELECT pvs.vendor_site_id
FROM mrp_sr_assignments msa
,mrp_sourcing_rules msr
,mrp_sr_receipt_org msro
,mrp_sr_source_org msso
,po_vendors pv
,po_vendor_sites_all pvs
WHERE 1 = 1
AND msa.sourcing_rule_id = msr.sourcing_rule_id
AND msr.sourcing_rule_id = msro.sourcing_rule_id
AND msro.sr_receipt_id = msso.sr_receipt_id
AND msso.allocation_percent = 100
AND TRUNC (SYSDATE) BETWEEN TRUNC (NVL
(msro.effective_date, SYSDATE)) AND TRUNC (NVL (msro.disable_date, SYSDATE))
AND msso.vendor_id = pv.vendor_id
AND pv.vendor_id = pvs.vendor_id
AND msso.vendor_site_id = pvs.vendor_site_id
AND msa.assignment_set_id = 2
AND assignment_type IN (6, 3)
AND msa.inventory_item_id = msi.inventory_item_id
AND msa.organization_id = msi.organization_id)
vendor_site_id
FROM mrp_gross_requirements mgr
,mtl_system_items_b msi
WHERE compile_designator = :p_plan
AND msi.inventory_item_id = mgr.inventory_item_id
AND msi.organization_id = :p_organization_id
AND mgr.inventory_item_id = NVL (:p_item_id, msi.inventory_item_id)
AND using_assembly_demand_date >= (SELECT repetitive_anchor_date
FROM mrp_parameters_v
WHERE organization_id =
:p_organization_id)
GROUP BY using_assembly_demand_date
,mgr.inventory_item_id
,msi.segment1
,DECODE (msi.planning_make_buy_code
,1, 'Make'
,2, 'Buy')
,msi.inventory_item_id
,msi.organization_id)
ORDER BY using_assembly_demand_date,segment1