You are on page 1of 7

SELECT je.

ae_header_id,
je.ae_line_num,
SUM(amount_dr - amount_cr) OVER(PARTITION BY je.account ORDER BY
je.ae_header_id, je.ae_line_num) AS running_total,
je.amount_dr,
je.amount_cr,
je.amount_dr - je.amount_cr AS line_net,
entered_dr,
entered_cr,
je.description,
je.currency_code,
je.PERIOD_NAME,
je.PERIOD_YEAR,
je.PERIOD_NUM,
je.QUARTER_NUM,
-- TO_CHAR(je.accounting_date, 'DD/Mon/RRRR') ACCOUNTING_DATE,
TO_CHAR(je.GL_TRANSFER_DATE, 'DD/Mon/RRRR') GL_TRANSFER_DATE,
je.code_combination_id,

company,
company_desc,
cost_center,
cost_center_desc,
account,
account_desc,
-- parent_acc,
Branch,
Branch_desc,
Channel,
Channel_desc,
LOB,
LOB_desc,
Product,
Product_desc,
Intercompany,
Intercompany_desc,
future_1,
future_2,

je.application_id,
je.entity_id,
je.entity_code,
je.source_id_int_1,
-- je.sub_trx_id,
-- je.sub_trx_number,
-- je.sub_third_part_id,
-- je.sub_third_part_name,
-- je.sub_third_part_num,
je.product_code,
je.je_category_name,
je.je_header_description,
TO_CHAR(je.accounting_date, 'DD/Mon/RRRR') AS accounting_date,
je.created_by,
POSTED_DATE,
Journal_Batch

from (SELECT je_lines.ae_header_id,


je_lines.ae_line_num,
NVL(je_lines.accounted_dr, 0) AS amount_dr,
NVL(je_lines.accounted_cr, 0) AS amount_cr,
NVL(je_lines.entered_dr, 0) entered_dr,
NVL(je_lines.entered_cr, 0) entered_cr,
je_lines.description,
je_lines.currency_code,
je_headers.PERIOD_NAME,
gl_periods.PERIOD_YEAR,
gl_periods.PERIOD_NUM,
gl_periods.QUARTER_NUM,
je_headers.GL_TRANSFER_DATE,
je_lines.code_combination_id,

cc.segment1 AS company,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
1,
cc.segment1) AS company_desc,
cc.segment2 AS cost_center,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
2,
cc.segment2) AS
cost_center_desc,
cc.segment3 AS account,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
3,
cc.segment3) AS account_desc,
cc.segment4 AS Branch,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
4,
cc.segment4) AS Branch_desc,
cc.segment5 AS Channel,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
5,
cc.segment5) AS Channel_desc,

cc.segment6 AS LOB,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
6,
cc.segment6) AS LOB_desc,

cc.segment7 AS Product,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
7,
cc.segment7) AS Product_desc,

cc.segment8 AS Intercompany,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
8,
cc.segment8) AS
Intercompany_desc,

cc.segment9 AS future_1,
cc.segment10 AS future_2,

je_headers.application_id,
ent.entity_id,
ent.entity_code,
ent.source_id_int_1,
trx.customer_trx_id,
TO_CHAR(trx.trx_number),
trx.bill_to_customer_id,
prt.party_name AS customer_name,
cust_acc.account_number AS customer_account_number,
app.product_code,
je_headers.je_category_name,
je_headers.description AS je_header_description,
je_headers.accounting_date,
trx.created_by,
(SELECT distinct gjh.POSTED_DATE
FROM gl_je_batches GLB,
gl_je_headers gjh,
gl_je_lines gjl,
gl_import_references gir,
xla_ae_lines xlal,
xla_ae_headers xlah,
xla_events xlae,
xla_transaction_entities xlate
WHERE GLB.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 gjl.je_line_num = gir.je_line_num
AND gir.gl_sl_link_table = xlal.gl_sl_link_table
AND gir.gl_sl_link_id = xlal.gl_sl_link_id
AND xlal.ae_header_id = xlah.ae_header_id
AND xlah.event_id = xlae.event_id
AND xlae.entity_id = xlate.entity_id
AND xlae.application_id = xlate.application_id
and xlal.ae_header_id = je_lines.ae_header_id
and xlal.gl_sl_link_id = je_lines.gl_sl_link_id
and xlal.gl_sl_link_table = je_lines.gl_sl_link_table)
POSTED_DATE,

(SELECT distinct b.name je_batch_name


FROM gl_je_batches b,
gl_je_headers h,
gl_je_lines l,
gl_import_references gir,
xla_ae_lines xlal,
xla_ae_headers xlah,
xla_events xlae
WHERE b.je_batch_id = h.je_batch_id
AND h.je_header_id = l.je_header_id
AND l.je_header_id = gir.je_header_id
AND l.je_line_num = gir.je_line_num
AND gir.gl_sl_link_table = xlal.gl_sl_link_table
AND gir.gl_sl_link_id = xlal.gl_sl_link_id
AND xlal.application_id = xlah.application_id
AND xlal.ae_header_id = xlah.ae_header_id
AND xlah.application_id = xlae.application_id
AND xlah.event_id = xlae.event_id
and xlal.ae_header_id = je_lines.ae_header_id
and xlal.gl_sl_link_id = je_lines.gl_sl_link_id
and xlal.gl_sl_link_table = je_lines.gl_sl_link_table)
Journal_Batch

FROM xla_ae_lines je_lines,


xla_ae_headers je_headers,
fnd_application app,
gl_code_combinations cc,
xla_transaction_entities ent,
ra_customer_trx_all trx,
hz_cust_accounts cust_acc,
hz_parties prt,
gl_import_references gl_link,
gl_periods

WHERE je_lines.ae_header_id = je_headers.ae_header_id


AND je_headers.gl_transfer_status_code = 'Y'
AND je_headers.PERIOD_NAME = gl_periods.PERIOD_NAME
and gl_periods.PERIOD_SET_NAME = 'Macro Calendar'
/* AND gl_periods.PERIOD_YEAR = :P_PERIOD_YEAR
AND gl_periods.PERIOD_NUM between :P_STAR_PERIOD_NUM AND
:P_END_PERIOD_NUM*/
AND gl_periods.PERIOD_YEAR = 2022
AND gl_periods.PERIOD_NUM between 9 AND 9
AND je_headers.application_id = app.application_id
AND je_lines.code_combination_id = cc.code_combination_id
AND je_headers.entity_id = ent.entity_id
AND ent.entity_code = 'TRANSACTIONS'
AND ent.source_id_int_1 = trx.customer_trx_id(+)
AND trx.bill_to_customer_id = cust_acc.cust_account_id(+)
AND cust_acc.party_id = prt.party_id(+)
AND je_lines.gl_sl_link_id = gl_link.gl_sl_link_id
AND je_lines.gl_sl_link_table = gl_link.gl_sl_link_table
union all
SELECT je_lines.ae_header_id,
je_lines.ae_line_num,
NVL(je_lines.accounted_dr, 0) AS amount_dr,
NVL(je_lines.accounted_cr, 0) AS amount_cr,
NVL(je_lines.entered_dr, 0) entered_dr,
NVL(je_lines.entered_cr, 0) entered_cr,
je_lines.description,
je_lines.currency_code,
je_headers.PERIOD_NAME,
gl_periods.PERIOD_YEAR,
gl_periods.PERIOD_NUM,
gl_periods.QUARTER_NUM,
je_headers.GL_TRANSFER_DATE,
je_lines.code_combination_id,

cc.segment1 AS company,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
1,
cc.segment1) AS company_desc,
cc.segment2 AS cost_center,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
2,
cc.segment2) AS
cost_center_desc,
cc.segment3 AS account,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
3,
cc.segment3) AS account_desc,
-- parent_account.ancestor_pk1_value AS parent_acc,
cc.segment4 AS Branch,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
4,
cc.segment4) AS Branch_desc,
cc.segment5 AS Channel,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
5,
cc.segment5) AS Channel_desc,

cc.segment6 AS LOB,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
6,
cc.segment6) AS LOB_desc,

cc.segment7 AS Product,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
7,
cc.segment7) AS Product_desc,

cc.segment8 AS Intercompany,
gl_flexfields_pkg.get_description_sql(cc.chart_of_accounts_id,
8,
cc.segment8) AS
Intercompany_desc,

cc.segment9 AS future_1,
cc.segment10 AS future_2,

je_headers.application_id,
ent.entity_id,
ent.entity_code,
ent.source_id_int_1,
rec.cash_receipt_id,
TO_CHAR(rec.receipt_number),
rec.pay_from_customer,
prt.party_name AS customer_name,
cust_acc.account_number AS customer_account_number,
app.product_code,
je_headers.je_category_name,
je_headers.description AS je_header_description,
je_headers.accounting_date,
rec.created_by,
(SELECT distinct gjh.POSTED_DATE
FROM gl_je_batches GLB,
gl_je_headers gjh,
gl_je_lines gjl,
gl_import_references gir,
xla_ae_lines xlal,
xla_ae_headers xlah,
xla_events xlae,
xla_transaction_entities xlate
WHERE GLB.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 gjl.je_line_num = gir.je_line_num
AND gir.gl_sl_link_table = xlal.gl_sl_link_table
AND gir.gl_sl_link_id = xlal.gl_sl_link_id
AND xlal.ae_header_id = xlah.ae_header_id
AND xlah.event_id = xlae.event_id
AND xlae.entity_id = xlate.entity_id
AND xlae.application_id = xlate.application_id
and xlal.ae_header_id = je_lines.ae_header_id
and xlal.gl_sl_link_id = je_lines.gl_sl_link_id
and xlal.gl_sl_link_table = je_lines.gl_sl_link_table)
POSTED_DATE,

(SELECT distinct b.name je_batch_name


FROM gl_je_batches b,
gl_je_headers h,
gl_je_lines l,
gl_import_references gir,
xla_ae_lines xlal,
xla_ae_headers xlah,
xla_events xlae
WHERE b.je_batch_id = h.je_batch_id
AND h.je_header_id = l.je_header_id
AND l.je_header_id = gir.je_header_id
AND l.je_line_num = gir.je_line_num
AND gir.gl_sl_link_table = xlal.gl_sl_link_table
AND gir.gl_sl_link_id = xlal.gl_sl_link_id
AND xlal.application_id = xlah.application_id
AND xlal.ae_header_id = xlah.ae_header_id
AND xlah.application_id = xlae.application_id
AND xlah.event_id = xlae.event_id
and xlal.ae_header_id = je_lines.ae_header_id
and xlal.gl_sl_link_id = je_lines.gl_sl_link_id
and xlal.gl_sl_link_table = je_lines.gl_sl_link_table)
Journal_Batch
FROM xla_ae_lines je_lines,
xla_ae_headers je_headers,
fnd_application app,
gl_code_combinations cc,
xla_transaction_entities ent,
ar_cash_receipts_all rec,
hz_cust_accounts cust_acc,
hz_parties prt,
gl_import_references gl_link,
gl_periods

WHERE je_lines.ae_header_id = je_headers.ae_header_id


AND je_headers.gl_transfer_status_code = 'Y'
AND je_headers.PERIOD_NAME = gl_periods.PERIOD_NAME
and gl_periods.PERIOD_SET_NAME = 'Macro Calendar'
/* AND gl_periods.PERIOD_YEAR = :P_PERIOD_YEAR
AND gl_periods.PERIOD_NUM between :P_STAR_PERIOD_NUM AND
:P_END_PERIOD_NUM*/
AND gl_periods.PERIOD_YEAR = 2022
AND gl_periods.PERIOD_NUM between 9 AND 9
AND je_headers.application_id = app.application_id
AND je_lines.code_combination_id = cc.code_combination_id
AND je_headers.entity_id = ent.entity_id
AND ent.entity_code = 'RECEIPTS'
AND ent.source_id_int_1 = rec.cash_receipt_id(+)
AND rec.pay_from_customer = cust_acc.cust_account_id(+)
AND cust_acc.party_id = prt.party_id(+)
AND je_lines.gl_sl_link_id = gl_link.gl_sl_link_id
AND je_lines.gl_sl_link_table = gl_link.gl_sl_link_table) je
WHERE NOT (je.amount_dr = 0 AND je.amount_cr = 0)
/* AND (je.cost_center = :P_cost_center OR :P_cost_center IS NULL)
AND (je.company = :P_Company OR :P_Company IS NULL)

AND je.account = :P_ACCOUNT_1


AND (UPPER(je.description) LIKE UPPER('%' || :P_LINE_DES || '%') OR
:P_LINE_DES IS NULL)*/

ORDER BY je.ae_header_id, je.ae_line_num

You might also like