SELECT
ac.customer_name Customer_Name ,
--------------------------------------------------
---Receivable Invoice with
receipt details
--------------------------------------------------
rtl.trx_number Trx_No, rtl.trx_date Trx_Dt,
rgd.gl_date GL_Dt , rct.line_number LINE_NO,
rct.quantity_invoiced LINE_QTY,
rct.unit_selling_price UNIT_SP,
(rct.revenue_amount) Line_Amt,
(rct.extended_amount) Dist_Amt,
(SELECT concatenated_segments FROM apps.gl_code_combinations_kfv
WHERE code_combination_id = rgd.code_combination_id) Acccount,
acr.receipt_number receipt_No, acr.receipt_date, acr.status,
acr.TYPE, acr.amount, acr.comments
FROM apps.ra_customer_trx_all rtl,
apps.ar_customers ac,
apps.ra_customer_trx_lines_all rct,
apps.ra_cust_trx_line_gl_dist_all rgd,
apps.ar_receivable_applications_all ara,
apps.ar_cash_receipts_all acr
WHERE 1 = 1
AND ac.customer_id = rtl.bill_to_customer_id
AND rct.customer_trx_id = rtl.customer_trx_id
AND rct.customer_trx_line_id = rgd.customer_trx_line_id
AND rtl.customer_trx_id = rgd.customer_trx_id
-- AND ara.status = 'APP'
AND ara.cash_receipt_id = acr.cash_receipt_id
AND ara.applied_customer_trx_id = rtl.customer_trx_id
-- AND rtl.TRX_NUMBER like
'15%'
and ac.customer_name like 'Ministry of Defence'
and rtl.trx_date between '01-jan-2016' and '31-dec-2016'
--ORDER BY rtl.org_id ;