22 October 2013

Requisition Aging Reporting

SQL is here

SELECT
       r.segment1 req_num,
       r.org_id req_org_id,
       xle.legal_entity_name,
       r.creation_date rcdate,
       rl.need_by_date,
       rl.to_person_id,
       ppf.full_name requestor_name,
       rl.deliver_to_location_id,
       hrl.location_code location_code,
       hrl1.description,
       hrl.attribute2 legacy_location_code,
       p.bill_to_location_id,
       p.segment1 po_num,
       p.vendor_id,
       pov.segment1 vendor_num,
       pov.vendor_name vendor_name,
       p.creation_date pcdate,
       rsh.receipt_num,
       rsh.creation_date rshcdate,
       rsh.created_by,
       pah.action_date,
       pah.employee_id,
       ai.invoice_num,
       ai.invoice_date,
       rl.unit_price,
       rl.quantity,
       r.authorization_status
  FROM po_req_distributions_all rd,
       po_requisition_lines_all rl,
       po_requisition_headers_all r,
       hr_locations_all hrl,
       per_all_people_f ppf,
       po_headers_all p,
       po_distributions_all d,
       ap_invoice_distributions_all apid,
       ap_invoices_all ai,
       rcv_shipment_lines rsl,
       rcv_shipment_headers rsh,
       po_action_history pah,
       po_vendors pov,
       xle_le_ou_ledger_v xle,
       gl_code_combinations_kfv gcc,
       hr_locations_all hrl1
WHERE     r.requisition_header_id = rl.requisition_header_id
       AND rl.requisition_line_id = rd.requisition_line_id
       AND rl.deliver_to_location_id = hrl.location_id
       AND rl.to_person_id = ppf.person_id
       AND ppf.effective_start_date < SYSDATE
       AND ppf.effective_end_date > SYSDATE
       AND rd.distribution_id = d.req_distribution_id(+)
       AND d.po_header_id = p.po_header_id(+)
       AND d.po_distribution_id = apid.po_distribution_id(+)
       AND apid.invoice_id = ai.invoice_id(+)
       AND p.po_header_id = rsl.po_header_id(+)
       AND rsl.shipment_header_id = rsh.shipment_header_id(+)
       AND r.requisition_header_id = pah.object_id(+)
       AND pah.object_type_code = 'REQUISITION'
       AND p.vendor_id = pov.vendor_id(+)
       AND ai.legal_entity_id = xle.legal_entity_id(+)
       AND ai.org_id = xle.operating_unit_id(+)
       AND rd.code_combination_id = gcc.code_combination_id
       AND p.bill_to_location_id = hrl1.location_id(+)

No comments: