Wednesday, 8 May 2013

SQL for AP->PO->SLA->GL for R12

/* Formatted on 5/8/2013 12:19:23 PM (QP5 v5.114.809.3010) */
SELECT   ph.segment1 po_number,
         aps.vendor_name,
         msi.segment1 item_number,
         msi.description item_description,
         'A/P PO Match' accrual_transaction,
         'AP*' SOURCE,
         (SELECT   organization_name
            FROM   apps.org_organization_definitions
           WHERE   organization_id = pd.destination_organization_id)
            org,
         ai.invoice_num doc_number,
         ai.invoice_date doc_date,
         aid.invoice_line_number line,
         pl.unit_meas_lookup_code uom,
         aid.quantity_invoiced quantity,
         aid.unit_price,
         (NVL (xdl.unrounded_accounted_dr, 0)
          - NVL (xdl.unrounded_accounted_cr, 0))
            accounted_amount,
         (NVL (xdl.unrounded_entered_cr, 0)
          - NVL (xdl.unrounded_entered_cr, 0))
            entered_amount,
         xal.currency_code
  FROM   apps.gl_je_headers gjh,
         apps.gl_je_lines gjl,
         apps.gl_import_references gir,
         apps.xla_ae_lines xal,
         apps.xla_ae_headers xah,
         apps.xla_events xe,
         apps.xla_event_types_tl xet,
         apps.xla_event_classes_tl xect,
         apps.xla_distribution_links xdl,
         apps.ap_invoice_distributions_all aid,
         apps.ap_invoices_all ai,
         apps.po_headers_all ph,
         apps.po_distributions_all pd,
         apps.po_lines_all pl,
         apps.ap_suppliers aps,
         apps.mtl_system_items_b msi
 WHERE       gjh.je_header_id = gjl.je_header_id
         AND gjh.je_header_id = gir.je_header_id
         AND gjl.je_header_id = gir.je_header_id
         AND gir.je_line_num = gjl.je_line_num
         AND gir.gl_sl_link_id = xal.gl_sl_link_id
         AND xal.ae_header_id = xah.ae_header_id
         AND xah.event_id = xe.event_id
         AND xe.event_type_code = xet.event_type_code
         AND xe.application_id = xet.application_id
         AND xet.LANGUAGE = USERENV ('LANG')
         AND xect.entity_code = xet.entity_code
         AND xect.event_class_code = xet.event_class_code
         AND xect.application_id = xe.application_id
         AND xect.LANGUAGE = USERENV ('LANG')
         AND xah.ae_header_id = xdl.ae_header_id
         AND xal.ae_line_num = xdl.ae_line_num
         AND xdl.source_distribution_type = 'AP_INV_DIST'
         AND xdl.source_distribution_id_num_1 = aid.invoice_distribution_id
         AND ai.invoice_id = aid.invoice_id
         AND aid.po_distribution_id = pd.po_distribution_id
         AND gjh.je_source = 'Payables'
         AND ph.po_header_id = pd.po_header_id
         AND pl.po_header_id = ph.po_header_id
         AND pd.po_line_id = pl.po_line_id
         AND pd.org_id = 83
         AND ph.org_id = 83
         AND ai.org_id = 83
         AND aid.org_id = 83
         AND gjl.code_combination_id = 1011
         AND ph.vendor_id = aps.vendor_id
         AND msi.inventory_item_id = pl.item_id
         AND msi.organization_id = pd.destination_organization_id

No comments:

Post a Comment