Pular para o conteúdo

Join entre AP/AR/XLA e GL

Join entre AP/AR/XLA e GL

Sergio, tudo bem ?
Obrigado pelas respostas anteriores. Aproveitando, gostaria de saber se poderia me ajudar mais uma vez ? heheeh
Como faço para buscar no GL informações do Payables e do Receivables ? Preciso buscar algumas informações.

Obrigado
Andreti


Para buscar informações de documentos contabilizados da maneira solicitada, precisaremos fazer um join entre as tabelas do Receivables (AR), Payables (AP), Subledger Accounting (XLA) e General Ledger (GL).

Vou usar como exemplo um código SQL que utilizo muito em meus trabalhos. Ele é composto por:

Query 1:

Receivables (AR)

  • ra_customer_trx_lines_all

Subledger Accounting (XLA)

  • xla_ae_headers
  • xla_ae_lines
  • xla_transaction_entities

General Ledger (GL)

  • gl_je_headers
  • gl_je_lines
  • gl_je_batches
  • gl_import_references

Query 2:

Payables (AP)

  • ap_invoice_lines_all

Subledger Accounting (XLA)

  • xla_ae_headers
  • xla_ae_lines
  • xla_transaction_entities

General Ledger (GL)

  • gl_je_headers
  • gl_je_lines
  • gl_je_batches
  • gl_import_references

Abaixo a instrução SQL completa:

SELECT gjh.period_name 
         ,gjh.je_header_id
         ,gjl.je_line_num
         ,gjh.je_source
         ,gjl.attribute12
         ,NVL(xte.source_id_int_1, -99)       customer_trx_id
         ,0                                   invoice_id
   FROM   XLA.xla_transaction_entities  xte
         ,AR .ra_customer_trx_lines_all rcta
         ,GL .gl_import_references      gir
         ,GL .gl_je_batches             gjb
         ,XLA.xla_ae_lines              xal
         ,GL .gl_je_lines               gjl
         ,XLA.xla_ae_headers            xah
         ,GL .gl_je_headers             gjh
   WHERE  rcta.line_type       = 'LINE'
   AND    rcta.line_number     = gjl.je_line_num
   AND    NVL
             (
              xte.source_id_int_1
             ,-99
             )                 = rcta.customer_trx_id
   AND    xte.ledger_id        = rcta.set_of_books_id             
   AND    xte.entity_id        = xah.entity_id
   AND    xah.ae_header_id     = xal.ae_header_id
   AND    xal.gl_sl_link_id    = gir.gl_sl_link_id
   AND    xal.gl_sl_link_table = gir.gl_sl_link_table  
   AND    gir.je_line_num      = gjl.je_line_num
   AND    gir.je_header_id     = gjh.je_header_id
   AND    gir.je_batch_id      = gjh.je_batch_id
   AND    gjb.je_batch_id      = gjh.je_batch_id
   AND    gjl.je_header_id     = gjh.je_header_id
   AND    gjh.je_source        = 'Receivables'
   AND    gjh.ledger_id        = p_ledger_id   
   AND    gjh.period_name      = p_period
   UNION ALL
   SELECT gjh.period_name 
         ,gjh.je_header_id
         ,gjl.je_line_num
         ,gjh.je_source
         ,gjl.attribute12
         ,0                               customer_trx_id
         ,NVL(xte.source_id_int_1, -99)   invoice_id
   FROM   XLA.xla_transaction_entities xte
         ,AP .ap_invoice_lines_all     aila
         ,GL .gl_import_references     gir
         ,GL .gl_je_batches            gjb
         ,XLA.xla_ae_lines             xal
         ,GL .gl_je_lines              gjl
         ,XLA.xla_ae_headers           xah
         ,GL.gl_je_headers             gjh
   WHERE  aila.line_number     = gjl.je_line_num
   AND    NVL
             (
              xte.source_id_int_1
             , -99
             )                 = aila.invoice_id
   AND    xte.ledger_id        = aila.set_of_books_id             
   AND    xte.entity_id        = xah.entity_id
   AND    xah.ae_header_id     = xal.ae_header_id
   AND    xal.gl_sl_link_id    = gir.gl_sl_link_id
   AND    xal.gl_sl_link_table = gir.gl_sl_link_table  
   AND    gir.je_line_num      = gjl.je_line_num
   AND    gir.je_header_id     = gjh.je_header_id
   AND    gir.je_batch_id      = gjh.je_batch_id
   AND    gjb.je_batch_id      = gjh.je_batch_id
   AND    gjl.je_header_id     = gjh.je_header_id
   AND    gjh.je_source        = 'Payables'
   AND    gjh.ledger_id        = p_ledger_id   
   AND    gjh.period_name      = p_period;

Você pode complementá-la e acrescentar informações de acordo com a sua necessidade. Talvez incluindo a XLA_EVENTS para incrementar (join com XLA_TRANSACTIONS_ENTITIES ou XLA_AE_HEADERS).

Espero que tenha ajudado ! Abraço !

Referências

Quão útil foi este post ?

Clique em uma estrela para classificar o post

nota média 4.8 / 5. Contagem de votos: 32

Sem votos ! Seja o primeiro a classificar !

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

plugins premium WordPress