SELECT iv.*,
(
LTRIM (RPAD (INITCAP (adr_line_1), 38, ' ')) ||
LTRIM (RPAD (INITCAP (adr_line_2), 38, ' ')) ||
LTRIM (RPAD (INITCAP (adr_line_3), 38, ' ')) ||
LTRIM (RPAD (INITCAP (adr_line_4), 38, ' ')) ||
LTRIM (RPAD (INITCAP (adr_line_5), 38, ' ')) ||
LTRIM (RPAD (DECODE (adr_line_6, adr_postcode, '', adr_line_6), 38, ' '))
||
adr_postcode
) address,
CASE
WHEN payment_method IS NULL OR payment_date IS NULL
THEN NULL
ELSE 'The Payments have been made by '
|| payment_method || ' on '
|| TO_CHAR (payment_date, 'DD/MM/RR') || '.'
END payment_info
FROM
(
SELECT DISTINCT
bpd_refno,
NULL apay_refno,
TO_CHAR (bpd_refno) grouping_id,
dutr_apay_payee_par_refno reference,
SYSDATE today,
s_parties.party_name (dutr_apay_payee_par_refno) name,
DECODE ( s_parties.get_par_type (dutr_apay_payee_par_refno),
'COM', 'Sir/Madam',
s_parties.party_name (dutr_apay_payee_par_refno ) ) saluatation_name,
COALESCE (hbm_user_description, hbm_description, bpd_ads_hbm_code) payment_method,
bpd_issued_date payment_date,
dutr_payee_address_refno
FROM dhp_uc_transactions,
dhp_uc_trans_hist,
benefit_payment_docs,
hb_payment_method_types
WHERE dutr_apay_dpt_code = 'LL'
AND duth_dutr_refno(+) = dutr_refno
AND bpd_refno IN (dutr_bpd_refno, duth_dutr_bpd_refno)
AND bpd_uc_dhp_pay_ind = 'Y'
AND :P_BPY331_JOB_RUN_ID IS NULL
AND bpd_uc_dhp_bpb_refno = :P_CREDITORS_BATCH_REF
AND hbm_code(+) = bpd_ads_hbm_code
UNION ALL
SELECT DISTINCT
NULL bpd_refno,
dutr_apay_refno,
CASE
WHEN dutr_apay_hbm_code = 'CHX' THEN
TO_CHAR (dutr_apay_payee_par_refno)
WHEN dutr_apay_hbm_code LIKE 'BACS%' THEN
TO_CHAR (dutr_apay_payee_par_refno) || ':'
|| dutr_sort_code || ':' || dutr_account_number
ELSE '::'
END grouping_id,
dutr_apay_payee_par_refno reference,
SYSDATE today,
s_parties.party_name (dutr_apay_payee_par_refno) name,
DECODE ( s_parties.get_par_type (dutr_apay_payee_par_refno),
'COM', 'Sir/Madam',
s_parties.party_name (dutr_apay_payee_par_refno ) ) saluatation_name,
COALESCE (hbm_user_description, hbm_description, dutr_apay_hbm_code) payment_method,
dutr_payment_date payment_date,
dutr_payee_address_refno
FROM dhp_uc_transactions,
dhp_uc_trans_hist,
hb_payment_method_types
WHERE dutr_apay_dpt_code = 'LL'
AND duth_dutr_refno(+) = dutr_refno
AND :P_CREDITORS_BATCH_REF IS NULL
AND :P_BPY331_JOB_RUN_ID IN (dutr_post_gpi_ref, duth_dutr_post_gpi_ref)
AND hbm_code(+) = dutr_apay_hbm_code
) iv,
addresses
WHERE adr_r
efno(+) = dutr_payee_address_refno