DCP

Thursday, 10 October 2013

AP to GL Drilldown (Encumbrance Transactions)


SELECT
  gjh.je_source source,
  gjh.je_category category,
  gjb.name batch_name,
  gjl.je_line_num line_num,
  gjh.actual_flag actual_flag,
  gjh.period_name period,
  gjl.effective_date gl_date,
  gcc.segment1 fund,
  gcc.segment2 FUNCTION,
  gcc.segment3 object,
  gcc.segment4 sub_object,
  gcc.segment5 org,
  gcc.segment6 yr,
  gcc.segment7 program,
  DECODE(SIGN(aid.amount),    -1,0,aid.amount) debit,
  DECODE(SIGN(aid.amount),1,0,-aid.amount) credit,
  gjh.je_category type,
  pha.segment1 purchase_document_num,
  pv.vendor_name,                                                   
  aia.invoice_num invoice_num,                                      
  TO_NUMBER(AID.DISTRIBUTION_LINE_NUMBER) invoice_distribution_num, 
  aid.expenditure_type,
  to_date(aia.invoice_date) trx_date
FROM
  apps.gl_je_batches jb,
  apps.gl_je_headers gjh,
  apps.gl_je_lines gjl,
  apps.gl_je_batches gjb,
  apps.gl_import_references gir,
  gl_code_combinations gcc,
  ap_encumbrance_lines_all ael ,
  ap_invoice_distributions_all Aid, 
  po_headers_all pha,
  po_distributions_all pda,
  po_vendors pv,
  ap_invoices_all aia,
  gl_period_statuses ps
WHERE
  jb.je_batch_id                    = gjh.je_batch_id
AND gjh.je_header_id                = gjl.je_header_id
AND gjl.je_header_id                = gir.je_header_id (+)
AND gjh.je_batch_id                 = gjb.je_batch_id
AND gjl.je_line_num                 = gir.je_line_num (+)
AND gjh.actual_flag                 = 'E'
AND gjh.je_source                   = 'Payables'
AND gjh.je_category                 = 'Purchase Invoices'
AND gjb.status                      = 'P'
AND gjh.status                      = 'P'
AND gjl.status                      = 'P'
AND gcc.code_combination_id         = gjl.code_combination_id
AND gir.gl_sl_link_id               = ael.gl_sl_link_id (+)
AND ael.invoice_distribution_id     = aid.invoice_distribution_id (+)
AND aid.po_distribution_id          = pda.po_distribution_id (+)
AND pda.po_header_id                = pha.po_header_id (+)
AND aid.invoice_id                  = aia.invoice_id (+)
AND aia.vendor_id                   = pv.vendor_id (+)
  -- change start
  -- user uses date range rather than period to run the report
AND ps.application_id = 101
AND gjh.period_name   = ps.period_name
AND PS.start_date     = to_date(TO_CHAR(gjl.effective_date, 'MON-YYYY'),
  'MON-YYYY')
AND ps.end_date = TRUNC(last_day(gjl.effective_date));
--and ps.period_name = 'SEP-14';

No comments:

Post a Comment