You are on page 1of 4

SELECT SQ_ARRECEIPTAPPLICATION.

CUSTOMER_ACCNT_ID C1_CUSTOMER_ACCNT_ID,
SQ_ARRECEIPTAPPLICATION.CUSTOMER_FIN_PROFL_ID C2_CUSTOMER_FIN_PROFL_ID,
SQ_ARRECEIPTAPPLICATION.RECEIPT_METHOD_ID C3_RECEIPT_METHOD_ID,
COALESCE(SQ_ARRECEIPTAPPLICATION.AMOUNT,0) C4_AMOUNT,
COALESCE(SQ_ARRECEIPTAPPLICATION.AMOUNT_APPLIED,0) C5_APPLIED_AMT,
COALESCE(SQ_ARRECEIPTAPPLICATION.DISCOUNT_AMOUNT,0) C6_DISCOUNT_AMT,
COALESCE(SQ_ARRECEIPTAPPLICATION.EARNED_DISCOUNT_AMT,0) C7_EARNED_DISCOUNT_AMT
,
COALESCE(SQ_ARRECEIPTAPPLICATION.UNEARNED_DISCOUNT_AMT,0) C8_UNEARNED_DISCOUNT
_AMT,
SQ_ARRECEIPTAPPLICATION.UNIDENTIFIED_AMT C9_UNIDENTIFIED_AMT,
SQ_ARRECEIPTAPPLICATION.UNAPPLIED_AMT C10_UNAPPLIED_AMT,
SQ_ARRECEIPTAPPLICATION.ON_ACCOUNT_AMT C11_ON_ACCOUNT_AMT,
SQ_ARRECEIPTAPPLICATION.CASH_CLAIMS_AMT C12_CASH_CLAIMS_AMT,
SQ_ARRECEIPTAPPLICATION.PREPAYMENT_AMT C13_PREPAYMENT_AMT,
LKP_CASH_RECEIPT_HIST_ALL.STATUS C14_RECEIPT_STATE,
SQ_ARRECEIPTAPPLICATION.RECEIPT_NUMBER C15_RECEIPT_NUM,
SQ_ARRECEIPTAPPLICATION.TRX_NUMBER C16_SALES_INVOICE_NUM,
SQ_ARRECEIPTAPPLICATION.RECEIPT_DATE C17_RECEIPT_DT,
SQ_ARRECEIPTAPPLICATION.APPLY_DATE C18_APPLIED_DT,
SQ_ARRECEIPTAPPLICATION.CONFIRMED_FLAG C19_CONFIRMED_FLG,
SQ_ARRECEIPTAPPLICATION.DISPLAY C20_DISPLAY_FLG,
SQ_ARRECEIPTAPPLICATION.CURRENCY_CODE C21_CURRENCY_CODE,
TO_CHAR(SQ_ARRECEIPTAPPLICATION.CREATED_BY) C22_CREATED_BY_ID,
TO_CHAR(SQ_ARRECEIPTAPPLICATION.LAST_UPDATED_BY) C23_CHANGED_BY_ID,
SQ_ARRECEIPTAPPLICATION.CREATION_DATE C24_CREATED_ON_DT,
SQ_ARRECEIPTAPPLICATION.LAST_UPDATE_DATE C25_CHANGED_ON_DT,
SQ_ARRECEIPTAPPLICATION.LAST_UPDATE_DATE C26_AUX1_CHANGED_ON_DT,
SQ_ARRECEIPTAPPLICATION.LAST_UPDATE_DATE C27_AUX2_CHANGED_ON_DT,
TO_CHAR(SQ_ARRECEIPTAPPLICATION.SET_OF_BOOKS_ID) C28_LEDGER_ID,
COALESCE(SQ_ARRECEIPTAPPLICATION.ACCTD_AMOUNT_APPLIED_FROM,0) C29_X_ACTIVITY_A
MT,
'I'
|| '~'
|| TO_CHAR(SQ_ARRECEIPTAPPLICATION.OLD_BANK_ID) C30_OLD_BANK_ID,
SQ_ARRECEIPTAPPLICATION.OLD_RECEIPT_ON_DT C31_OLD_RECEIPT_ON_DT,
SQ_ARRECEIPTAPPLICATION.OLD_RECEIPT_NUM C32_OLD_RECEIPT_NUM,
SQ_ARRECEIPTAPPLICATION.DEPOSIT_DATE C33_DEPOSIT_DATE,
SQ_ARRECEIPTAPPLICATION.BILLING_DATE C34_BILLING_DATE,
SQ_ARRECEIPTAPPLICATION.APPLICATION_REF_NUM C35_APPLICATION_REF_NUM,
SQ_ARRECEIPTAPPLICATION.REC_ACTIVITY_NAME C36_REC_ACTIVITY_NAME,
SQ_ARRECEIPTAPPLICATION.INVOICE_CREATED_BY C37_INVOICE_CREATED_BY,
SQ_ARRECEIPTAPPLICATION.PAYMENT_TRXN_EXTENSION_ID C38_PAYMENT_TRXN_EXT_ID,
SQ_ARRECEIPTAPPLICATION.RECEIPT_PROGRAM_NAME C39_RECEIPT_PROGRAM_NAME,
SQ_ARRECEIPTAPPLICATION.STATUS C40_STATUS,
SQ_ARRECEIPTAPPLICATION.BANK_ACCOUNT_ID C41_BANK_ACCOUNT_ID,
SQ_ARRECEIPTAPPLICATION.RECEIVABLE_APPLICATION_ID C42_RECEIVABLE_APPLICATION_I
D,
SQ_ARRECEIPTAPPLICATION.LEGAL_ENTITY_ID C43_LEGAL_ENTITY_ID,
SQ_ARRECEIPTAPPLICATION.GL_TRANSFER_DATE
FROM
(
/* Subselect from Custom_SDE_ORA_ARReceiptApplication.WC_AR_RECEIPT_XACT_FS_SQ
_AR_RCPT_APPL
*/
SELECT AR_CASH_RECEIPTS_ALL.AMOUNT AMOUNT,
AR_CASH_RECEIPTS_ALL.CASH_RECEIPT_ID CASH_RECEIPT_ID,
AR_CASH_RECEIPTS_ALL.CREATED_BY CREATED_BY,
AR_CASH_RECEIPTS_ALL.CREATION_DATE CREATION_DATE,
AR_CASH_RECEIPTS_ALL.CURRENCY_CODE CURRENCY_CODE,

AR_CASH_RECEIPTS_ALL.CUSTOMER_SITE_USE_ID CUSTOMER_FIN_PROFL_ID,
AR_CASH_RECEIPTS_ALL.LAST_UPDATE_DATE LAST_UPDATE_DATE,
AR_CASH_RECEIPTS_ALL.LAST_UPDATED_BY LAST_UPDATED_BY,
AR_CASH_RECEIPTS_ALL.LEGAL_ENTITY_ID LEGAL_ENTITY_ID,
AR_CASH_RECEIPTS_ALL.ORG_ID ORG_ID,
AR_CASH_RECEIPTS_ALL.RECEIPT_DATE RECEIPT_DATE,
AR_CASH_RECEIPTS_ALL.RECEIPT_METHOD_ID RECEIPT_METHOD_ID,
AR_CASH_RECEIPTS_ALL.RECEIPT_NUMBER RECEIPT_NUMBER,
AR_RECEIVABLE_APPLICATIONS_ALL.ACCTD_AMOUNT_APPLIED_FROM ACCTD_AMOUNT_APPLIE
D_FROM,
AR_RECEIVABLE_APPLICATIONS_ALL.APPLY_DATE APPLY_DATE,
AR_RECEIVABLE_APPLICATIONS_ALL.CONFIRMED_FLAG CONFIRMED_FLAG,
AR_RECEIVABLE_APPLICATIONS_ALL.DISPLAY DISPLAY,
AR_RECEIVABLE_APPLICATIONS_ALL.RECEIVABLE_APPLICATION_ID RECEIVABLE_APPLICAT
ION_ID,
AR_RECEIVABLE_APPLICATIONS_ALL.SET_OF_BOOKS_ID SET_OF_BOOKS_ID,
AR_RECEIVABLE_APPLICATIONS_ALL.STATUS STATUS,
CE_BANK_ACCT_USES_ALL.BANK_ACCOUNT_ID BANK_ACCOUNT_ID,
RA_CUSTOMER_TRX_ALL.BILL_TO_CUSTOMER_ID BILL_TO_CUSTOMER_ID,
CASE
WHEN AR_PAYMENT_SCHEDULES_ALL.TRX_NUMBER = 'Prepayment'
THEN AR_PAYMENT_SCHEDULES_ALL.AMOUNT_APPLIED
ELSE 0
END PREPAYMENT_AMT,
CASE
WHEN AR_RECEIVABLE_APPLICATIONS_ALL.STATUS = 'ACC'
THEN AR_RECEIVABLE_APPLICATIONS_ALL.AMOUNT_APPLIED
ELSE 0
END ON_ACCOUNT_AMT,
CASE
WHEN AR_RECEIVABLE_APPLICATIONS_ALL.STATUS = 'APP'
THEN AR_RECEIVABLE_APPLICATIONS_ALL.AMOUNT_APPLIED
ELSE 0
END AMOUNT_APPLIED,
CASE
WHEN AR_RECEIVABLE_APPLICATIONS_ALL.STATUS='APP'
THEN RA_CUSTOMER_TRX_ALL.TRX_NUMBER
WHEN AR_RECEIVABLE_APPLICATIONS_ALL.STATUS='OTHER ACC'
THEN AR_RECEIVABLE_APPLICATIONS_ALL.APPLICATION_REF_NUM
WHEN AR_RECEIVABLE_APPLICATIONS_ALL.STATUS IN ('ACTIVITY','ACC')
THEN AR_PAYMENT_SCHEDULES_ALL.TRX_NUMBER
ELSE NULL
END TRX_NUMBER,
CASE
WHEN AR_RECEIVABLE_APPLICATIONS_ALL.STATUS
= 'OTHER ACC'
AND AR_RECEIVABLE_APPLICATIONS_ALL.APPLICATION_REF_TYPE = 'CLAIM'
THEN AR_RECEIVABLE_APPLICATIONS_ALL.AMOUNT_APPLIED
ELSE 0
END CASH_CLAIMS_AMT,
CASE
WHEN AR_RECEIVABLE_APPLICATIONS_ALL.STATUS = 'UNAPP'
THEN AR_RECEIVABLE_APPLICATIONS_ALL.AMOUNT_APPLIED
ELSE 0
END UNAPPLIED_AMT,
CASE
WHEN AR_RECEIVABLE_APPLICATIONS_ALL.STATUS = 'UNID'
THEN AR_RECEIVABLE_APPLICATIONS_ALL.AMOUNT_APPLIED
ELSE 0
END UNIDENTIFIED_AMT,
COALESCE(AR_RECEIVABLE_APPLICATIONS_ALL.EARNED_DISCOUNT_TAKEN,0) EARNED_DISC

OUNT_AMT,
COALESCE(AR_RECEIVABLE_APPLICATIONS_ALL.UNEARNED_DISCOUNT_TAKEN,0) UNEARNED_
DISCOUNT_AMT,
COALESCE(AR_RECEIVABLE_APPLICATIONS_ALL.UNEARNED_DISCOUNT_TAKEN,0) + COALESC
E( AR_RECEIVABLE_APPLICATIONS_ALL.EARNED_DISCOUNT_TAKEN,0) DISCOUNT_AMOUNT,
TO_CHAR(AR_CASH_RECEIPTS_ALL.PAY_FROM_CUSTOMER) CUSTOMER_ACCNT_ID,
AR_RECEIVABLE_APPLICATIONS_ALL.APPLICATION_REF_NUM APPLICATION_REF_NUM,
DECODE(AR_PAYMENT_SCHEDULES_ALL.CLASS,'PMT',AR_RECEIVABLES_TRX_ALL.NAME, DEC
ODE(SIGN(AR_RECEIVABLE_APPLICATIONS_ALL.APPLIED_PAYMENT_SCHEDULE_ID), -1,AR_RECE
IVABLES_TRX_ALL.NAME, NULL)) REC_ACTIVITY_NAME,
IBY_FNDCPT_TX_EXTENSIONS.INSTR_ASSIGNMENT_ID PAYMENT_TRXN_EXTENSION_ID,
LAG(CE_BANK_ACCT_USES_ALL.BANK_ACCOUNT_ID) OVER (PARTITION BY AR_CASH_RECEIP
TS_ALL.PAY_FROM_CUSTOMER ORDER BY AR_CASH_RECEIPTS_ALL.RECEIPT_DATE) OLD_BANK_ID
,
LAG(AR_CASH_RECEIPTS_ALL.RECEIPT_DATE) OVER (PARTITION BY AR_CASH_RECEIPTS_A
LL.PAY_FROM_CUSTOMER ORDER BY AR_CASH_RECEIPTS_ALL.RECEIPT_DATE) OLD_RECEIPT_ON_
DT,
LAG(AR_CASH_RECEIPTS_ALL.RECEIPT_NUMBER) OVER (PARTITION BY AR_CASH_RECEIPTS
_ALL.PAY_FROM_CUSTOMER ORDER BY AR_CASH_RECEIPTS_ALL.RECEIPT_DATE) OLD_RECEIPT_N
UM,
RA_CUSTOMER_TRX_ALL.CREATED_BY INVOICE_CREATED_BY,
AR_CASH_RECEIPTS_ALL.DEPOSIT_DATE BILLING_DATE,
RA_CUSTOMER_TRX_ALL.TRX_DATE DEPOSIT_DATE,
FND_CONCURRENT_PROGRAMS_VL.USER_CONCURRENT_PROGRAM_NAME RECEIPT_PROGRAM_NAME
,
XLA_AE_HEADERS.GL_TRANSFER_DATE GL_TRANSFER_DATE
FROM ((((APPS.AR_CASH_RECEIPTS_ALL AR_CASH_RECEIPTS_ALL
LEFT OUTER JOIN APPS.CE_BANK_ACCT_USES_ALL CE_BANK_ACCT_USES_ALL
ON AR_CASH_RECEIPTS_ALL.REMIT_BANK_ACCT_USE_ID=CE_BANK_ACCT_USES_ALL.BANK_ACCT
_USE_ID)
INNER JOIN ((APPS.AR_RECEIVABLE_APPLICATIONS_ALL AR_RECEIVABLE_APPLICATIONS_AL
L
LEFT OUTER JOIN APPS.AR_PAYMENT_SCHEDULES_ALL AR_PAYMENT_SCHEDULES_ALL
ON AR_RECEIVABLE_APPLICATIONS_ALL.APPLIED_PAYMENT_SCHEDULE_ID=AR_PAYMENT_SCHED
ULES_ALL.PAYMENT_SCHEDULE_ID)
LEFT OUTER JOIN APPS.RA_CUSTOMER_TRX_ALL RA_CUSTOMER_TRX_ALL
ON AR_RECEIVABLE_APPLICATIONS_ALL.APPLIED_CUSTOMER_TRX_ID=RA_CUSTOMER_TRX_ALL.
CUSTOMER_TRX_ID)
ON AR_CASH_RECEIPTS_ALL.CASH_RECEIPT_ID
=AR_RECEIVABLE_APPLIC
ATIONS_ALL.CASH_RECEIPT_ID)
LEFT OUTER JOIN APPS.AR_RECEIVABLES_TRX_ALL AR_RECEIVABLES_TRX_ALL
ON AR_RECEIVABLE_APPLICATIONS_ALL.RECEIVABLES_TRX_ID =AR_RECEIVABLES_TRX_ALL.R
ECEIVABLES_TRX_ID
AND AR_RECEIVABLE_APPLICATIONS_ALL.ORG_ID
=AR_RECEIVABLES_TRX_ALL.O
RG_ID)
left outer join apps.XLA_AE_HEADERS XLA_AE_HEADERS
ON AR_RECEIVABLE_APPLICATIONS_ALL.event_id=xla_ae_headers.event_id
LEFT OUTER JOIN APPS.FND_CONCURRENT_PROGRAMS_VL FND_CONCURRENT_PROGRAMS_VL
ON AR_CASH_RECEIPTS_ALL.PROGRAM_APPLICATION_ID=FND_CONCURRENT_PROGRAMS_VL.APPL
ICATION_ID
AND AR_CASH_RECEIPTS_ALL.PROGRAM_ID
=FND_CONCURRENT_PROGRAMS_VL.CONC
URRENT_PROGRAM_ID)
LEFT OUTER JOIN APPS.IBY_FNDCPT_TX_EXTENSIONS IBY_FNDCPT_TX_EXTENSIONS
ON AR_CASH_RECEIPTS_ALL.PAYMENT_TRXN_EXTENSION_ID
= IBY_FNDCPT_TX_EXTENS
IONS.TRXN_EXTENSION_ID
WHERE (1
=1)
AND ( (AR_RECEIVABLE_APPLICATIONS_ALL.LAST_UPDATE_DATE >= TO_DATE(SUBSTR('2015
-10-18 00:34:29',0,19),'YYYY-MM-DD HH24:MI:SS')
OR RA_CUSTOMER_TRX_ALL.LAST_UPDATE_DATE
>= TO_DATE(SUBSTR('2015
-10-18 00:34:29',0,19),'YYYY-MM-DD HH24:MI:SS')

OR AR_CASH_RECEIPTS_ALL.LAST_UPDATE_DATE
>= TO_DATE(SUBSTR('2015
-10-18 00:34:29',0,19),'YYYY-MM-DD HH24:MI:SS')) )
) SQ_ARRECEIPTAPPLICATION,
(
/* Subselect from Custom_SDE_ORA_ARReceiptApplication.WC_AR_RECEIPT_XACT_FS_SQ
_RECEIPT_HIST_ALL
*/
SELECT AR_CASH_RECEIPT_HISTORY_ALL.STATUS STATUS,
AR_CASH_RECEIPT_HISTORY_ALL.CASH_RECEIPT_HISTORY_ID CASH_RECEIPT_HISTORY_ID,
AR_CASH_RECEIPT_HISTORY_ALL.CASH_RECEIPT_ID CASH_RECEIPT_ID,
RANK() OVER (PARTITION BY AR_CASH_RECEIPT_HISTORY_ALL.CASH_RECEIPT_ID ORDER
BY AR_CASH_RECEIPT_HISTORY_ALL.CASH_RECEIPT_HISTORY_ID DESC) RANK
FROM APPS.AR_CASH_RECEIPT_HISTORY_ALL AR_CASH_RECEIPT_HISTORY_ALL
WHERE (1=1)
) LKP_CASH_RECEIPT_HIST_ALL
WHERE (1
=1)
AND (SQ_ARRECEIPTAPPLICATION.CASH_RECEIPT_ID=LKP_CASH_RECEIPT_HIST_ALL.CASH_RECE
IPT_ID (+)
AND LKP_CASH_RECEIPT_HIST_ALL.RANK (+)
= 1)
;