You are on page 1of 6

select bill_to_customer_id,

customer_account_number,
customer_name,
sum(amount_dr) amount_dr,
sum(amount_cr) amount_cr,
sum(amount_dr) - sum(amount_cr) balance
from (SELECT je.amount_dr,
je.amount_cr,
trx_number,
bill_to_customer_id,
customer_name,
customer_account_number,
account,
account_desc,
TO_CHAR(je.accounting_date, 'DD/Mon/RRRR') AS accounting_date,
Journal_Batch,
entity_code

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_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 1 AND 1*/
AND je_headers.accounting_date BETWEEN :P_FROM_DATE
AND :P_TO_DATE
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
and cc.segment3 like '10402%'
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 1 AND 1*/
AND je_headers.accounting_date BETWEEN :P_FROM_DATE
AND :P_TO_DATE
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
and cc.segment3 like '10402%') je
WHERE NOT (je.amount_dr = 0 AND je.amount_cr = 0))
-- where customer_account_number = 12003
group by bill_to_customer_id,
customer_account_number,
customer_name

You might also like