Friday, 28 October 2016

Purchase order to AP Invoice Detail Query

/* Formatted on 10/26/2016 1:41:32 PM (QP5 v5.114.809.3010) */
SELECT   prh.SEGMENT1 "PO_Rrequisition_ #",
         Prl.LINE_NUM "PO_Rrequisition_Line_ #",
         (Prl.UNIT_PRICE * Prl.QUANTITY) "PO_Rrequisition_Amount",
         Prd.GL_ENCUMBERED_DATE "PO_Req_Encumbered_Date",
         Prd.GL_ENCUMBERED_PERIOD_NAME "PO_Req_Period",
         poh.SEGMENT1 "PO_ #",
         pol.LINE_NUM "PO_Line_ #",
         (pol.UNIT_PRICE * pol.QUANTITY) "PO_Amount",
         Pod.GL_ENCUMBERED_DATE "PO_Encumbered_Date",
         Pod.GL_ENCUMBERED_PERIOD_NAME "PO_Period",
         Api.INVOICE_NUM "Invoice #",
         Apl.LINE_NUMBER "Invoice_Line_ #",
         Apl.AMOUNT "Invoice_Amount",
         Apl.PERIOD_NAME "Invoice_Period",
         Api.GL_DATE "INN_Gl_Date"
  FROM   po_requisition_headers_all prh,
         po_requisition_lines_all prl,
         po_req_distributions_all prd,
         po_distributions_all pod,
         po_headers_all poh,
         po_lines_all pol,
         ap_invoice_distributions_all apd,
         ap_invoice_lines_all apl,
         ap_invoices_all api
 WHERE       1 = 1
         AND prh.requisition_header_id = prl.requisition_header_id
         AND prl.requisition_line_id = prd.requisition_line_id
         AND prh.SEGMENT1 in('7') -- PO Requisition #
--         And  poh.SEGMENT1 = '1083'  -- Purchase Order #
--         AND api.invoice_num = 'CRINV00930'  -- AP Invoice #
         AND prd.distribution_id = pod.req_distribution_id(+)
         AND pol.po_line_id(+) = pod.po_line_id
         AND poh.po_header_id(+) = pol.po_header_id
         AND pod.po_distribution_id = apd.PO_DISTRIBUTION_ID(+)
         AND api.invoice_id(+) = apd.invoice_id
         AND api.invoice_id = apl.invoice_id(+)


No comments:

Post a Comment