Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 12

spool c:\CLIENT_queries\ap_acct_bal.

lis

column difference format 999999999999

select
(sum(gjl.accounted_dr)-sum(gjl.accounted_cr)) + sum(ap_gb_enc.amount) -
sum(ap_enc.amount) difference ,
gjl.code_combination_id
from
apps.gl_je_lines gjl,
apps.gl_je_headers gjh,
apps.gl_je_batches gjb,
apps.gl_encumbrance_types get,
(
select
sum(aid.amount) amount,
aid.dist_code_combination_id code_combination_id
from
apps.ap_invoice_distributions_all aid
where
nvl(aid.encumbered_flag,'N') = 'Y'
and
aid.set_of_books_id = 69
group by
aid.dist_code_combination_id
) ap_enc,
(
select
sum(gbp.accounted_dr)-sum(gbp.accounted_cr) amount,
gbp.code_combination_id
from
apps.gl_bc_packets gbp,
apps.gl_encumbrance_types get
where
gbp.status_code = 'A'
and
get.encumbrance_type_id = gbp.encumbrance_type_id
and
gbp.set_of_books_id = 69
and
get.encumbrance_type = 'Invoice Encumbrance'
group by
gbp.code_combination_id
) ap_gb_enc
where
gjl.je_header_id = gjh.je_header_id
and
gjh.je_batch_id = gjb.je_batch_id
and
get.encumbrance_type_id = gjh.encumbrance_type_id
and
ap_enc.code_combination_id = gjl.code_combination_id
and
get.encumbrance_type = 'Invoice Encumbrance'
and
gjb.set_of_books_id = 69
and
gjh.je_source in ('Payables')
and
ap_gb_enc.code_combination_id(+) = gjl.code_combination_id
group by
gjl.code_combination_id
having
(sum(gjl.accounted_dr)-sum(gjl.accounted_cr)) + sum(ap_gb_enc.amount) -
sum(ap_enc.amount) <> 0
/
spool off

set lines 300


set pages 60

rem the PO encumbrances generated from the PO module always post at detail
rem with the encumbrance type "obligation". This implies that encumbrances for the
rem PO distribution lines should always exists when the PO's are created.
rem
rem According to this behavior the following should be true.
rem
rem Unit_price * quantity_open = gl_po_encumbrances
rem
rem The quantity_open in this case is the quantity_ordered - quantity_cancelled
rem
rem When a PO is Finally closed, is outstanding balance in the GL should be 0.
rem
rem In the client all PO's are cut in a single currency, CAD.
rem

rem the following query will look at all encumbered PO's or approved PO's and locate the
generated
rem encumbrances. THe encumbered_amount should match what is in the gl. But in
case this
column is not
rem consitently used, we will compare to the quantities ordered and unit price.
rem

rem In essence this is what happens when a PO gets created from an accounting
standpoint.
rem

rem After a PO is approved and the funds are reserved, the PO encumbrance engines
rem fires off a process that generates a GL entry in GL_BC_PACKETS, which is a
temporary
location
rem for the encumbrance journals. The same process fires for corrections and
cancellations.

rem after successfull funds reservation a record gets intoduce into GL_BC_PACKETS,
which
rem is an object that closely resembles a journal entry line.

rem If we have a 100 PO distribution line, the end result is an entry for 100 with the
rem encumbrance type "Obligation"

rem Once the "Program Create Journal" gets run, this entry from GL_BC_PACKETS
gets
removed
rem and gets created as a permanent Journal encumbrance in the GL for the same
amount.

rem This Journal will remain in place until the PO line is matched, finally closed or
rem cancelled. It is essentially an audit trail for the transaction.

rem the following query will identify the cases where the amount in the GL does not
match
rem what the PO module has on file.
rem
rem

ttitle "PO with Encumbrance discrepencies with the GL"

col "Organization ID" format 999999999999999


col "PO Number" format a15
col "Line Number" format 99999999999
col "PO_DISTRIBUTION" format 999999999999999
col "Qty Ord" format 9999999
col "Qty Bill" format 99999999
col "Qty Can" format 9999999
col "Enc Amount Col" format 99999999999999
col "GL Enc Amount" format 9999999999999
col "Price" format 9999999
col "PO Cancel?" format a11
col "PO Appr?" format a8
col "Line Closed?" format a12
col "Line Canc?" format a10
col "Line Code" format a9
col "Ship Canc?" format a10
col "Ship Code" format a9
col "Ship App?" format a9
col "Ship Clsd?" format a10
col "Account" format a40
col "Period" format a8

spool c:\CLIENT_queries\po_enc_problem.lis

select
ph.org_id "Organization ID",
ph.segment1 "PO Number",
nvl(ph.cancel_flag,'N') "PO Cancel?",
nvl(ph.approved_flag,'N') "PO Appr?",
pl.line_num "Line Number",
nvl(pl.closed_flag,'N') "Line Closed?",
nvl(pl.cancel_flag,'N') "Line Canc?",
nvl(pl.closed_code,'OPEN') "Line Code",
nvl(pll.cancel_flag,'N') "Ship Canc?",
nvl(pll.closed_code,'OPEN') "Ship Code",
nvl(pll.approved_flag,'N') "Ship App?",
nvl(pll.closed_flag,'N') "Ship Clsd?",
pd.po_distribution_id "PO_DISTRIBUTION",
nvl(pd.quantity_ordered,0) "Qty Ord",
nvl(pd.quantity_billed,0) "Qty Bill",
nvl(pd.quantity_cancelled,0) "Qty Can",
nvl(pl.unit_price,0) "Price",
pd.encumbered_amount "Enc Amount Col",
round
(
nvl(pl.unit_price,0)*
(
nvl(pd.quantity_ordered,0)-nvl(pd.quantity_cancelled,0)
)
,0
) "Enc Amount",
round(nvl(gl.enc_amount,0)+nvl(gl_bc.enc_amount,0),0) "GL Enc Amount",
gcc.segment1||'-'||gcc.segment2||'-'||gcc.segment3||'-'||gcc.segment4||'-'||gcc.segment5
"Account",
pd.gl_encumbered_period_name "Period"
from
apps.po_lines_all pl,
apps.po_headers_all ph,
(
select
to_number(gir.reference_3) po_distribution_id,
sum(nvl(gjl.accounted_dr,0)-nvl(gjl.accounted_cr,0)) enc_amount
from
apps.gl_je_lines gjl,
apps.gl_je_headers gjh,
apps.gl_je_batches gjb,
apps.gl_import_references gir,
apps.gl_encumbrance_types get
where
get.encumbrance_type_id = gjh.encumbrance_type_id and
gir.je_header_id = gjl.je_header_id and
gir.je_line_num = gjl.je_line_num and
gjl.je_header_id = gjh.je_header_id and
gjh.je_batch_id = gjb.je_batch_id and
gir.reference_1 = 'PO' and
get.encumbrance_type in ('Obligation','Invoice Encumbrance') and
gjb.set_of_books_id = 69 and
gjb.status = 'P'
group by
gir.reference_3
) gl /* PO Encumbrances in the GL */,
(
select
to_number(gbp.reference3) po_distribution_id,
sum(nvl(gbp.accounted_dr,0)-nvl(gbp.accounted_cr,0)) enc_amount
from
apps.gl_bc_packets gbp,
apps.gl_encumbrance_types get
where
get.encumbrance_type in ('Obligation','Invoice Encumbrance') and
get.encumbrance_type_id = gbp.encumbrance_type_id and
gbp.reference1 = 'PO' and
gbp.set_of_books_id = 69 and
gbp.status_code = 'A'
group by
gbp.reference3
) gl_bc /* BC_PAcket Entries not in the GL yet */,
apps.po_line_locations_all pll,
apps.gl_code_combinations gcc,
apps.po_distributions_all pd
where
pd.po_header_id = ph.po_header_id
and
pl.po_line_id = pd.po_line_id
and
pll.line_location_id = pd.line_location_id
and
gcc.code_combination_id = pd.code_combination_id
and
gl.po_distribution_id(+) = pd.po_distribution_id
and
gl_bc.po_distribution_id(+) = pd.po_distribution_id
and
pd.po_release_id is null /* Exluding releases on this pass */
and
nvl(pd.encumbered_flag,'N') = 'Y' /* Only encumbered lines */
and
pd.set_of_books_id = 69
and
(
round(
nvl(pl.unit_price,0)
*
decode(pll.closed_code,
'FINALLY CLOSED',0,
1
)
*
(nvl(pd.quantity_ordered,0)
-
nvl(pd.quantity_cancelled,0)
)
)
<>
round(
nvl(gl.enc_amount,0)
+
nvl(gl_bc.enc_amount,0)
)
)
order by ph.org_id,ph.segment1,pd.po_distribution_id
/

spool off
set lines 300
set pages 60

rem the AP encumbrances generated from the AP module always post at detail
rem with the encumbrance type "Invoice Encumbrance"". This implies that
encumbrances for
the
rem AP distribution lines should always exists when the Invoices are created initially.
rem
rem According to this beahvior the following should be true.
rem
rem The invoice amount should be encumbered in full for every distribution lines
rem The offsetting entries won't be visible in this case since summary posting has been
enabled
rem for this reason only batches of type CJE will be analysed. These transactions
rem represent the transactions generated by the funds reservation process. The ofsetting
rem entries are actually generated by the AP to GL transfer program and are assumed to
be
rem correct at this time.
rem
rem In the CLIENT all Invoices are cut in a single currency, CAD.
rem

rem the following query will look at all invoices and locate the generated
rem encumbrances. THe encumbered_amount should match what is in the gl.
rem

rem In essence this is what happens when an invoice gets created from an accounting
standpoint.
rem

rem After an invoice is approved and the funds are reserved, the AP encumbrance
engines
rem fires off a process that generates a GL entry in GL_BC_PACKETS, which is a
temporary
location
rem for the encumbrance journals. The same process fires for corrections and
cancellations.

rem after successfull funds reservation a record gets introduce into GL_BC_PACKETS,
which
rem is an object that closely resembles a journal entry line.
rem If we have a 100 distribution line, the end result is an entry for 100 with the
rem encumbrance type "Invoice Encumbrance"

rem Once the "Program Create Journal" gets runned, this entry from GL_BC_PACKETS
gets
removed
rem and gets created as a permannet Journal encumbrance in the GL for the same
amount.

rem the following query will identify the cases where the amount in the GL does not
match
rem what the AP module has on file.
rem
rem

ttitle "Unmatched Invoices with Encumbrance discrepencies with the GL"

col "Organization ID" format 999999999999999


col "PO Number" format a15
col "Line Number" format 99999999999
col "PO_DISTRIBUTION" format 999999999999999
col "Qty Ord" format 9999999
col "Qty Bill" format 99999999
col "Qty Can" format 9999999
col "Enc Amount Col" format 99999999999999
col "GL Enc Amount" format 9999999999999
col "Price" format 9999999
col "Rel Cancel?" format a11
col "Rel Appr?" format a8
col "Line Closed?" format a12
col "Line Canc?" format a10
col "Line Code" format a9
col "Ship Canc?" format a10
col "Ship Code" format a9
col "Ship App?" format a9
col "Ship Clsd?" format a10
col "Account" format a40
col "Period" format a8
col "Release Num" format 999999999999

spool c:\CLIENT_queries\po_rel_problem.lis

select
ai.org_id "Organization ID",
ai.invoice_num "Inv Number",
aid.distribution_line_number "Inv Line",
aid.amount_encumbered "Enc Amount Col",
round(aid.amount) "Amount",
round(nvl(gl.enc_amount,0)+nvl(gl_bc.enc_amount,0),0) "GL Enc Amount",
gcc.segment1||'-'||gcc.segment2||'-'||gcc.segment3||'-'||gcc.segment4||'-'||gcc.segment5
"Account"
from
(
select
to_number(gir.reference_3) distribution_line_number,
to_number(gir.reference_2) invoice_id,
sum(nvl(gjl.accounted_dr,0)-nvl(gjl.accounted_cr,0)) enc_amount
from
apps.gl_je_lines gjl,
apps.gl_je_headers gjh,
apps.gl_je_batches gjb,
apps.gl_import_references gir,
apps.gl_encumbrance_types get
where
get.encumbrance_type_id = gjh.encumbrance_type_id and
gir.je_header_id = gjl.je_header_id and
gir.je_line_num = gjl.je_line_num and
gjl.je_header_id = gjh.je_header_id and
gjh.je_batch_id = gjb.je_batch_id and
gir.reference_6 = 'AP Invoices' and
get.encumbrance_type = 'Invoice Encumbrance' and
gjb.status = 'P' and
gjb.set_of_books_id = 69
group by
gir.reference_3,gir.reference_2
) gl /* PO Encumbrances in the GL */,
(
select
to_number(gbp.reference3) distribution_line_number,
to_number(gbp.reference2) invoice_id,
sum(nvl(gbp.accounted_dr,0)-nvl(gbp.accounted_cr,0)) enc_amount
from
apps.gl_bc_packets gbp,
apps.gl_encumbrance_types get
where
get.encumbrance_type = 'Invoice Encumbrance' and
gbp.je_source_name = 'Payables' and
get.encumbrance_type_id = gbp.encumbrance_type_id and
gbp.status_code = 'A' and
gbp.set_of_books_id = 69
group by
gbp.reference3,gbp.reference2
) gl_bc /* BC_PAcket Entries not in the GL yet */,
apps.gl_code_combinations gcc,
apps.ap_invoices_all ai,
apps.ap_invoice_distributions_all aid
where
aid.invoice_id = ai.invoice_id
and
gcc.code_combination_id = aid.dist_code_combination_id
and
gl.distribution_line_number(+) = aid.distribution_line_number
and
gl.invoice_id(+) = aid.invoice_id
and
gl_bc.distribution_line_number(+) = aid.distribution_line_number
and
gl_bc.invoice_id(+) = aid.invoice_id
and
nvl(aid.encumbered_flag,'N') = 'Y' /* Only encumbered lines */
and
aid.set_of_books_id = 69
and
(
round(
nvl(aid.base_amount,aid.amount)
)
<>
round(
nvl(gl.enc_amount,0)
+
nvl(gl_bc.enc_amount,0)
)
)
order by ai.org_id,ai.invoice_num,aid.distribution_line_number
/

spool off

spool c:\CLIENT_queries\po_acct_bal.lis

column difference format 999999999999

select
(sum(gjl.accounted_dr)-sum(accounted_cr)) + sum(po_gb_enc.amount) -
sum(po_enc.amount)
difference ,
gjl.code_combination_id
from
apps.gl_je_lines gjl,
apps.gl_je_headers gjh,
apps.gl_je_batches gjb,
apps.gl_encumbrance_types get,
(
select
sum(pl.unit_price
*
decode(pll.closed_code,
'FINALLY CLOSED',0,
1
)
*
(pd.quantity_ordered - pd.quantity_cancelled - pd.quantity_billed)) amount,
pd.code_combination_id
from
apps.po_distributions_all pd,
apps.po_line_locations_all pll,
apps.po_lines_all pl
where
pd.line_location_id = pll.line_location_id
and
pd.po_line_id = pl.po_line_id
and
nvl(pd.encumbered_flag,'N') = 'Y'
and
pd.set_of_books_id = 69
group by
pd.code_combination_id
) po_enc,
(
select
sum(gbp.accounted_dr)-sum(gbp.accounted_cr) amount,
gbp.code_combination_id
from
apps.gl_bc_packets gbp,
apps.gl_encumbrance_types get
where
gbp.status_code = 'A'
and
get.encumbrance_type_id = gbp.encumbrance_type_id
and
gbp.set_of_books_id = 69
and
get.encumbrance_type = 'Obligation'
group by
gbp.code_combination_id
) po_gb_enc
where
gjl.je_header_id = gjh.je_header_id
and
gjh.je_batch_id = gjb.je_batch_id
and
get.encumbrance_type_id = gjh.encumbrance_type_id
and
po_enc.code_combination_id = gjl.code_combination_id
and
get.encumbrance_type = 'Obligation'
and
gjb.set_of_books_id = 69
and
gjh.je_source in ('Purchasing','Payables')
and
po_gb_enc.code_combination_id(+) = gjl.code_combination_id
group by
gjl.code_combination_id
having
(sum(gjl.accounted_dr)-sum(accounted_cr)) + sum(po_gb_enc.amount) -
sum(po_enc.amount)
<> 0
/

spool off

You might also like