Account Analysis
Account Analysis
Account Analysis
*,
sum(balance) over (order by trunc(accounting_date) nulls first,
je_header_id,je_line_num nulls first) closing_balance from(
SELECT
L.CURRENCY_CODE,
GJS.USER_JE_SOURCE_NAME CAT,
USER_JE_CATEGORY_NAME,
JH.NAME,
L.DESCRIPTION,
L.ACCOUNTING_DATE,
JH.POSTING_ACCT_SEQ_VALUE LEDGER_DOCUMENT,
H.DOC_SEQUENCE_VALUE,
GCC.SEGMENT1,
GCC.SEGMENT2,
GCC.SEGMENT3,
GCC.SEGMENT4,
GCC.SEGMENT5,
GCC.SEGMENT6,
GCC.SEGMENT7,
NVL (L.ENTERED_DR, 0) ENTERED_DR,
NVL (L.ENTERED_CR, 0) ENTERED_CR,
NVL (L.ACCOUNTED_DR, 0) ACCOUNTED_DR,
NVL (L.ACCOUNTED_CR, 0) ACCOUNTED_CR,
NVL (L.ACCOUNTED_DR, 0) -
NVL (L.ACCOUNTED_CR, 0) BALANCE,
CASE
WHEN XTE.APPLICATION_ID = 140 AND XTE.ENTITY_CODE = 'TRANSACTIONS'
THEN
(SELECT FAV.ASSET_NUMBER FROM FA_ADDITIONS_VL FAV,
FA_TRANSACTION_HEADERS FTH
WHERE FTH.TRANSACTION_HEADER_ID = XTE.SOURCE_ID_INT_1
AND FAV.ASSET_ID = FTH.ASSET_ID)||';'||XTE.TRANSACTION_NUMBER
WHEN XTE.APPLICATION_ID = 140 AND XTE.ENTITY_CODE = 'DEPRECIATION'
THEN
(SELECT FAV .ASSET_NUMBER FROM FA_ADDITIONS_VL FAV WHERE
FAV.ASSET_ID=XTE.TRANSACTION_NUMBER)
ELSE
XTE.TRANSACTION_NUMBER
END
TRANSACTION_NUMBER,
CASE
WHEN XTE.APPLICATION_ID=260 AND XTE.ENTITY_CODE='CE_EXTERNAL' THEN
(
SELECT HP.PARTY_NAME
FROM
CE_EXTERNAL_TRANSACTIONS CET,
CE_BAT_TRANSFERS CBT ,
HZ_PARTIES HP WHERE
CET.TRANSACTION_ID=XTE.SOURCE_ID_INT_1
AND CET.TRANSFER_ID=CBT.TRANSFER_ID
AND HP.PARTY_ID=CBT.PAYEE_PARTY_ID
)
WHEN L.PARTY_TYPE_CODE = 'S'
THEN
(SELECT VENDOR_NAME
FROM POZ_SUPPLIERS_V
WHERE VENDOR_ID = L.PARTY_ID
)
WHEN L.PARTY_TYPE_CODE='C' THEN
(SELECT HP.PARTY_NAME
FROM HZ_PARTIES HP, HZ_CUST_ACCOUNTS HCA
WHERE
HCA.CUST_ACCOUNT_ID = L.PARTY_ID
AND HP.PARTY_ID=HCA.PARTY_ID
and rownum<2)
WHEN (XTE.APPLICATION_ID=200 AND L.PARTY_ID IS NULL) THEN
(SELECT PARTY_NAME FROM
HZ_PARTIES HP,
AP_INVOICES_ALL AI
WHERE
AI.INVOICE_ID=XTE.SOURCE_ID_INT_1
AND HP.PARTY_ID=AI.PARTY_ID
)
ELSE NULL
END
VENDOR_NAME,
CASE
WHEN XTE.APPLICATION_ID = 200 AND XTE.ENTITY_CODE = 'AP_INVOICES'
THEN
AP_INVOICES_UTILITY_PKG.GET_PO_NUMBER_LIST (XTE.SOURCE_ID_INT_1)
END
PO_NUM,
CASE
WHEN XTE.APPLICATION_ID = 200 AND XTE.ENTITY_CODE = 'AP_INVOICES'
THEN
AP_INVOICES_UTILITY_PKG.GET_RECEIPT_NUMBER (XTE.SOURCE_ID_INT_1)
END
RECEIPT_NUM,
H.AE_HEADER_ID JE_HEADER_ID,
L.AE_LINE_NUM JE_LINE_NUM,
DECODE(JH.STATUS,'P','Posted','UnPosted')POSTING_STATUS
FROM XLA_TRANSACTION_ENTITIES XTE,
GL_CODE_COMBINATIONS GCC,
XLA_AE_HEADERS H,
XLA_AE_LINES L,
XLA_EVENTS E,
GL_IMPORT_REFERENCES GIR,
GL_JE_HEADERS JH,
XLA_SUBLEDGERS XSL,
GL_JE_SOURCES_VL GJS,
GL_LEDGERS GL,
GL_JE_CATEGORIES CAT,
GL_PERIODS GP
WHERE XTE.ENTITY_ID = E.ENTITY_ID
AND H.EVENT_ID = E.EVENT_ID
AND H.APPLICATION_ID = E.APPLICATION_ID
AND XTE.ENTITY_ID = H.ENTITY_ID
AND H.AE_HEADER_ID = L.AE_HEADER_ID
AND L.CODE_COMBINATION_ID = GCC.CODE_COMBINATION_ID
AND H.BALANCE_TYPE_CODE = 'A'
--AND JH.STATUS = 'P'
AND XTE.APPLICATION_ID = H.APPLICATION_ID
AND H.APPLICATION_ID = L.APPLICATION_ID
AND H.APPLICATION_ID = XSL.APPLICATION_ID
AND XSL.JE_SOURCE_NAME = GJS.JE_SOURCE_NAME
AND JH.JE_SOURCE = GJS.JE_SOURCE_NAME
AND H.GL_TRANSFER_STATUS_CODE = 'Y'
AND GIR.GL_SL_LINK_ID = L.GL_SL_LINK_ID
AND GIR.GL_SL_LINK_TABLE = 'XLAJEL'
AND GIR.JE_HEADER_ID = JH.JE_HEADER_ID
AND GJS.JE_SOURCE_NAME = NVL (:P_SOURCE, GJS.JE_SOURCE_NAME)
AND GL.LEDGER_ID = H.LEDGER_ID
AND GL.LEDGER_ID = :P_LEDGER_ID
AND CAT.JE_CATEGORY_NAME = JH.JE_CATEGORY
AND JH.PERIOD_NAME=GP.PERIOD_NAME
AND GL.PERIOD_SET_NAME = GP.PERIOD_SET_NAME
AND GP.ADJUSTMENT_PERIOD_FLAG = 'N'
AND H.PERIOD_NAME=GP.PERIOD_NAME
AND GP.PERIOD_YEAR || LPAD (GP.PERIOD_NUM, 2, 0) BETWEEN :P_FROM_PERIOD
AND :P_TO_PERIOD
AND CAT.JE_CATEGORY_NAME = NVL (:P_CATEGORY, CAT.JE_CATEGORY_NAME)
AND GCC.SEGMENT1 = NVL (:P_COMPANY, GCC.SEGMENT1)
AND GCC.SEGMENT2 = NVL (:P_BUSINESS_UNIT, GCC.SEGMENT2)
AND GCC.SEGMENT3 = NVL (:P_FUNCTIONS, GCC.SEGMENT3)
AND GCC.SEGMENT4 = NVL (:P_PRODUCT, GCC.SEGMENT4)
AND GCC.SEGMENT5 = NVL (:P_ACCOUNT, GCC.SEGMENT5)
--AND GCC.SEGMENT6 = NVL (:P_FUTURE, GCC.SEGMENT6)
--AND GCC.SEGMENT7 = NVL (:P_FUTURE2, GCC.SEGMENT7)
UNION ALL
SELECT
JEH.CURRENCY_CODE,
SRC.USER_JE_SOURCE_NAME CAT,
USER_JE_CATEGORY_NAME,
JEH.NAME,
JEL.DESCRIPTION,
JEL.EFFECTIVE_DATE,
JEH.POSTING_ACCT_SEQ_VALUE,
NULL ,
GCC.SEGMENT1,
GCC.SEGMENT2,
GCC.SEGMENT3,
GCC.SEGMENT4,
GCC.SEGMENT5,
GCC.SEGMENT6,
GCC.SEGMENT7,
NVL (JEL.ENTERED_DR, 0) ENTERED_DR,
NVL (JEL.ENTERED_CR, 0) ENTERED_CR,
NVL (JEL.ACCOUNTED_DR, 0) ACCOUNTED_DR,
NVL (JEL.ACCOUNTED_CR, 0) ACCOUNTED_CR,
NVL (JEL.ACCOUNTED_DR, 0) -
NVL (JEL.ACCOUNTED_CR, 0) BALANCE,
NULL TRANSACTION_NUMBER,
NULL VENDOR_NAME,
NULL PO_NUM,
NULL RECEIPT_NUM,
JEL.JE_HEADER_ID,
JEL.JE_LINE_NUM,
DECODE(JEH.STATUS,'P','Posted','UnPosted')POSTING_STATUS
FROM GL_JE_BATCHES JEB,
GL_JE_HEADERS JEH,
GL_JE_LINES JEL,
GL_CODE_COMBINATIONS GCC,
GL_JE_CATEGORIES CAT,
GL_JE_SOURCES SRC,
GL_LEDGERS GL,
GL_PERIODS GP
WHERE JEB.JE_BATCH_ID = JEH.JE_BATCH_ID
AND JEH.JE_HEADER_ID = JEL.JE_HEADER_ID
--AND JEH.STATUS = 'P'
AND JEL.CODE_COMBINATION_ID = GCC.CODE_COMBINATION_ID
AND JEB.AVERAGE_JOURNAL_FLAG = 'N' --- not consider average journal
AND JEH.ACTUAL_FLAG = 'A'
AND SRC.JE_SOURCE_NAME = JEH.JE_SOURCE
AND CAT.JE_CATEGORY_NAME = JEH.JE_CATEGORY
AND SRC.JE_SOURCE_NAME = NVL (:P_SOURCE, SRC.JE_SOURCE_NAME)
AND GL.LEDGER_ID = JEH.LEDGER_ID
AND CAT.JE_CATEGORY_NAME = NVL (:P_CATEGORY, CAT.JE_CATEGORY_NAME)
AND GL.LEDGER_ID = :P_LEDGER_ID
AND GL.PERIOD_SET_NAME = GP.PERIOD_SET_NAME
AND GP.ADJUSTMENT_PERIOD_FLAG = 'N'
AND GP.PERIOD_NAME=JEH.PERIOD_NAME
AND GP.PERIOD_YEAR || LPAD (GP.PERIOD_NUM, 2, 0) BETWEEN :P_FROM_PERIOD
AND :P_TO_PERIOD
AND SRC.JE_SOURCE_NAME NOT IN
(SELECT JE_SOURCE_NAME FROM XLA_SUBLEDGERS)
AND GCC.SEGMENT1 = NVL (:P_COMPANY, GCC.SEGMENT1)
AND GCC.SEGMENT2 = NVL (:P_BUSINESS_UNIT, GCC.SEGMENT2)
AND GCC.SEGMENT3 = NVL (:P_FUNCTIONS, GCC.SEGMENT3)
AND GCC.SEGMENT4 = NVL (:P_PRODUCT, GCC.SEGMENT4)
AND GCC.SEGMENT5 = NVL (:P_ACCOUNT, GCC.SEGMENT5)
UNION ALL
SELECT
NULL CURRENCY_CODE,
'Opening Balance' CAT,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL ,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
SUM(NVL (BAL.BEGIN_BALANCE_DR, 0) -
NVL (BAL.BEGIN_BALANCE_CR, 0)) BALANCE,
NULL TRANSACTION_NUMBER,
NULL VENDOR_NAME,
NULL PO_NUM,
NULL RECEIPT_NUM,
-1 JE_HEADER_ID,
-1 JE_LINE_NUM,
NULL
FROM
GL_BALANCES BAL,
GL_LEDGERS GL,
GL_CODE_COMBINATIONS GCC
WHERE BAL.ACTUAL_FLAG = 'A'
AND BAL.LEDGER_ID = GL.LEDGER_ID
AND GCC.CODE_COMBINATION_ID=BAL.CODE_COMBINATION_ID
AND GCC.SEGMENT1 = NVL (:P_COMPANY, GCC.SEGMENT1)
AND GCC.SEGMENT2 = NVL (:P_BUSINESS_UNIT, GCC.SEGMENT2)
AND GCC.SEGMENT3 = NVL (:P_FUNCTIONS, GCC.SEGMENT3)
AND GCC.SEGMENT4 = NVL (:P_PRODUCT, GCC.SEGMENT4)
AND GCC.SEGMENT5 = NVL (:P_ACCOUNT, GCC.SEGMENT5)
AND BAL.CURRENCY_CODE = GL.CURRENCY_CODE
AND BAL.PERIOD_YEAR || LPAD (BAL.PERIOD_NUM, 2, 0) =
:P_FROM_PERIOD
AND GL.LEDGER_ID = :P_LEDGER_ID
)a
order by trunc(accounting_date) nulls first,je_header_id,je_line_num nulls first