0% found this document useful (0 votes)
8 views

Old Dunning Letter DM Code

Uploaded by

Raviraj Padman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Old Dunning Letter DM Code

Uploaded by

Raviraj Padman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

select * from

(SELECT DISTINCT
idt.dunning_id dunning_id1,
ct.trx_number invoice_number,
hca.account_number accountnumber,--||'-'||hcsa.site_use_id
hp.party_name,
hcsa.location billto,
ar.due_date original_due_date,
(ar.amount_due_original) original_amount_due,
--round((ar.amount_due_remaining),2)
(CASE WHEN ct.attribute8 is not null and ct.attribute12 is null
AND AR.AMOUNT_DUE_ORIGINAL>to_number(ct.attribute9) THEN
round((ar.amount_due_remaining-to_number(ct.attribute9)),2)
ELSE round((ar.amount_due_remaining),2) END) as amount_due_remaining,
ar.invoice_currency_code currency,
ar.DEL_CONTACT_EMAIL_ADDRESS,
nvl(ied.financial_charge,0) finance_charges,
LOC2.location_id location_id,
LOC2.address1 remit_to_address1,
LOC2.address2 remit_to_address2,
LOC2.address3 remit_to_address3,
LOC2.address4 remit_to_address4,
LOC2.city remit_to_city,
LOC2.state remit_to_state,
LOC2.postal_code remit_to_postal_code,
LOC2.province remit_to_province,
t2.territory_short_name remit_to_country_desc,
TO_CHAR(ct.last_update_date,'YYYY-MM-DD"T"HH24:MI:SS') last_update_date,
ct.last_updated_by last_updated_by,
TO_CHAR(ct.creation_date,'YYYY-MM-DD"T"HH24:MI:SS') creation_date,
ct.created_by created_by,
ct.TRX_DATE invdate,
(trunc(sysdate)- TRUNC(ar.due_date)) DAYS,
ct.last_update_login last_update_login,
nvl(inte.interest_rate,0) as interest_rate ,
ter.name payment_term,
sysdate+14 next_date,
sysdate,
xle.name ||'-'||hcsa.location le_billto,
decode (xle.country, 'PE',xlep.attribute7,xle.name) legal_entity_name, -- W4
changes
--W5 Change
case when (select distinct bu.name from HR_ORGANIZATION_UNITS_F_TL bu where
bu.ORGANIZATION_ID=:p_bu_id) ='IM AT BU' THEN
xle.Address_Line_1 ||', '||chr(10)||nvl(xle.Address_Line_2,'') ||
decode(xle.Address_Line_2,null,'',', ')||nvl(xle.Address_Line_3,'') ||
decode(xle.Address_Line_3,null,'',', ')||
xle.Town_or_city ||' '||nvl(xle.Region_1,'') ||
decode(xle.Region_1,null,'',', ')||xle.Region_2 ||' '||
nvl(xle.ADDR_ELEMENT_ATTRIBUTE2,'') ||
decode(xle.ADDR_ELEMENT_ATTRIBUTE2,null,'',', ') ||
nvl(xle.PROVINCE,'') ||decode(xle.PROVINCE,null,'',', ') ||
nvl(xle.COUNTY,'') ||decode(xle.COUNTY,null,'',', ') ||
xle.Postal_code ||', '||xle.country
ELSE
replace(xle.Address_Line_1 ||','||nvl(xle.Address_Line_2,'') ||
decode(xle.Address_Line_2,null,'',',')||nvl(xle.Address_Line_3,'') ||
decode(xle.Address_Line_3,null,'',',')
||decode (xle.country, 'FI',xle.postal_code||','||
xle.town_or_city,xle.town_or_city)--||xle.Town_or_city
||' '||nvl(xle.Region_1,'') ||decode(xle.Region_1,null,'',',')||xle.Region_2 ||'
'||
nvl(xle.ADDR_ELEMENT_ATTRIBUTE2,'') ||
decode(xle.ADDR_ELEMENT_ATTRIBUTE2,null,'',',') ||
nvl(xle.PROVINCE,'') ||decode(xle.PROVINCE,null,'',',') ||
nvl(xle.COUNTY,'') ||decode(xle.COUNTY,null,'',',')
||decode (xle.country, 'FI',null ,xle.postal_code)--||xle.Postal_code
||','||xle.country,',,', ',')
END as Primary_address,
xle.Address_Line_1 as PRIMARY_ADDRESS1,
xle.Town_or_city ||' '||xle.Region_2 ||' '||xle.Postal_code as PRIMARY_CITY,
xle.country as PRIMARY_COUNTRY,

(select to_char(flv.description) from fnd_lookup_values flv


where flv.LANGUAGE = 'US'
and flv.lookup_type = 'IRM_DUNNING_REMITTANCE'
and nvl(enabled_flag,'Y')='Y'
and rownum <2
--Commented by Veda W4 and substr (xle.name, 1, length (flv.meaning)) =
flv.meaning) as REMIT_DETAILS,
and substr (xle.name, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) )
= substr (flv.meaning, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) )) as REMIT_DETAILS,
(select to_char(flv.tag) from fnd_lookup_values flv
where flv.LANGUAGE = 'US'
and nvl(enabled_flag,'Y')='Y'
and rownum <2
and flv.lookup_type = 'IRM_DUNNING_REMITTANCE'
--Commented by Veda W4 and substr (xle.name, 1, length (flv.meaning)) =
flv.meaning) as
and substr (xle.name, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) )
= substr (flv.meaning, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) )) REMIT_EMAIL_DETAILS,
decode(ied.locale,'en-US',null,
(select to_char(flv.tag) from fnd_lookup_values flv
where flv.LANGUAGE = 'US'
and nvl(enabled_flag,'Y')='Y'
and rownum <2
and ied.locale <> 'en-US'
and flv.lookup_type = 'IRM_LATAM_REMITTANCE_CONTACT'
--Commented by Veda W4 and substr (xle.name, 1, length (flv.meaning)) =
flv.meaning) as
and substr (xle.name, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) )
= substr (flv.meaning, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) ))) LATAM_EMAIL,
NULL name
,(select distinct bu.name from HR_ORGANIZATION_UNITS_F_TL bu where
bu.ORGANIZATION_ID=:p_bu_id) BU
,ct.attribute9 Dispute_amount
--added by veda
,(select rctl.attribute8
from ra_customer_trx_lines_all rctl
where rctl.customer_trx_id = ct.customer_trx_id
and rctl.attribute8 is not null
and rownum <2
group by rctl.attribute8 ) faipo_num
,
(select trunc(rctl.attribute_date1)
from ra_customer_trx_lines_all rctl
where rctl.customer_trx_id = ct.customer_trx_id
and rctl.attribute_date1 is not null
and rownum <2
group by rctl.attribute_date1 ) faipo_date
FROM
iex_dunnings ied,
HZ_LOCATIONS LOC2,
hz_parties hp,
AR_REMIT_TO_LOCS_ALL REMIT_LOC2,
iex_dunning_transactions idt,
ar_payment_schedules_all ar,
ra_customer_trx_all ct,
hz_cust_site_uses_all hcsa,
hz_cust_accounts hca,
fnd_territories_vl t2,
XLE_ENTITY_PROFILES xlep,
(select le.* ,hz.ADDR_ELEMENT_ATTRIBUTE2, hz.PROVINCE ,hz.county
from XLE_FIRSTPARTY_INFORMATION_V le,
HZ_LOCATIONS hz
where le.location_id = hz.location_id) xle,
HZ_CUST_PROFILE_AMTS_F inte
,RA_TERMS_TL Ter
WHERE
ied.dunning_id = idt.dunning_id
and hp.party_id = hca.party_id
and idt.payment_schedule_id = ar.payment_schedule_id
and ar.customer_trx_id = ct.customer_trx_id
and ct.bill_to_site_use_id = hcsa.site_use_id
and ct.remit_to_address_seq_id = REMIT_LOC2.ADDRESS_LOC_SEQ_ID
and REMIT_LOC2.location_id = LOC2.location_id(+)
and LOC2.country = t2.territory_code (+)
AND ar.customer_id = HCA.CUST_ACCOUNT_ID
AND ct.legal_entity_id = xle.legal_entity_id
--and inte.Site_use_id(+)=hcsa.Site_use_id
and hca.CUST_ACCOUNT_ID=inte.CUST_ACCOUNT_ID(+)
--and ct.attribute8 is null
AND (CASE WHEN ct.attribute8 is null then 'Yes'
ELSE (CASE WHEN ct.attribute12 is not null then 'Yes'
WHEN ct.attribute12 is null AND
(AR.AMOUNT_DUE_ORIGINAL>TO_NUMBER(ct.attribute9)) THEN 'Yes'
ELSE 'No' End) END)='Yes'
and ter.language='US'
and ar.term_id=ter.term_id(+)
and ct.creation_date >= To_date('01/03/2022','DD/MM/YYYY')
--order by 2,ar.due_date
and xlep.name=xle.name
union
SELECT distinct
idt.dunning_id dunning_id1,
ct.trx_number invoice_number,
hca.account_number accountnumber, --||'-'||hcsa.site_use_id
hp.party_name,
hcsa.location billto,
ar.due_date original_due_date,
(ar.amount_due_original) original_amount_due,
--(ar.amount_due_remaining)
(CASE WHEN ct.attribute8 is not null and ct.attribute12 is null
AND AR.AMOUNT_DUE_ORIGINAL>to_number(ct.attribute9) THEN
round((ar.amount_due_remaining-to_number(ct.attribute9)),2)
ELSE round((ar.amount_due_remaining),2) END) as amount_due_remaining,
ar.invoice_currency_code currency,
ar.DEL_CONTACT_EMAIL_ADDRESS,
nvl(ied.financial_charge,0) finance_charges,
LOC2.location_id location_id,
LOC2.address1 remit_to_address1,
LOC2.address2 remit_to_address2,
LOC2.address3 remit_to_address3,
LOC2.address4 remit_to_address4,
LOC2.city remit_to_city,
LOC2.state remit_to_state,
LOC2.postal_code remit_to_postal_code,
LOC2.province remit_to_province,
t2.territory_short_name remit_to_country_desc,
TO_CHAR(ct.last_update_date,'YYYY-MM-DD"T"HH24:MI:SS') last_update_date,
ct.last_updated_by last_updated_by,
TO_CHAR(ct.creation_date,'YYYY-MM-DD"T"HH24:MI:SS') creation_date,
ct.created_by created_by,
ct.TRX_DATE invdate,
(trunc(sysdate)- TRUNC(ar.due_date)) DAYS,
ct.last_update_login last_update_login,
nvl(inte.interest_rate,0) as interest_rate ,
ter.name payment_term,
sysdate+14 next_date, --Changed by Veda from 7 to 14
sysdate,
xle.name ||'-'||hcsa.location le_billto,
decode (xle.country, 'PE',xlep.attribute7,xle.name) legal_entity_name, -- W4
changes
--W5 Chnage
case when (select distinct bu.name from HR_ORGANIZATION_UNITS_F_TL bu where
bu.ORGANIZATION_ID=:p_bu_id) ='IM AT BU' THEN
xle.Address_Line_1 ||', '||chr(10)||nvl(xle.Address_Line_2,'') ||
decode(xle.Address_Line_2,null,'',', ')||nvl(xle.Address_Line_3,'') ||
decode(xle.Address_Line_3,null,'',', ')||
xle.Town_or_city ||' '||nvl(xle.Region_1,'') ||
decode(xle.Region_1,null,'',', ')||xle.Region_2 ||' '||
nvl(xle.ADDR_ELEMENT_ATTRIBUTE2,'') ||
decode(xle.ADDR_ELEMENT_ATTRIBUTE2,null,'',', ') ||
nvl(xle.PROVINCE,'') ||decode(xle.PROVINCE,null,'',', ') ||
nvl(xle.COUNTY,'') ||decode(xle.COUNTY,null,'',', ') ||
xle.Postal_code ||', '||xle.country
ELSE
replace(xle.Address_Line_1 ||','||nvl(xle.Address_Line_2,'') ||
decode(xle.Address_Line_2,null,'',',')||nvl(xle.Address_Line_3,'') ||
decode(xle.Address_Line_3,null,'',',')
||decode (xle.country, 'FI',xle.postal_code||','||
xle.town_or_city,xle.town_or_city)--||xle.Town_or_city
||' '||nvl(xle.Region_1,'') ||decode(xle.Region_1,null,'',',')||xle.Region_2 ||'
'||
nvl(xle.ADDR_ELEMENT_ATTRIBUTE2,'') ||
decode(xle.ADDR_ELEMENT_ATTRIBUTE2,null,'',',') ||
nvl(xle.PROVINCE,'') ||decode(xle.PROVINCE,null,'',',') ||
nvl(xle.COUNTY,'') ||decode(xle.COUNTY,null,'',',')
||decode (xle.country, 'FI',null ,xle.postal_code)--||xle.Postal_code
||','||xle.country,',,',',')
END as Primary_address,
xle.Address_Line_1 as PRIMARY_ADDRESS1,
xle.Town_or_city ||' '||xle.Region_2 ||' '||xle.Postal_code as PRIMARY_CITY,
xle.country as PRIMARY_COUNTRY,

(select to_char(flv.description) from fnd_lookup_values flv


where flv.LANGUAGE = 'US'
and flv.lookup_type = 'IRM_DUNNING_REMITTANCE'
and nvl(enabled_flag,'Y')='Y'
and rownum <2
--Commented by Veda W4 and substr (xle.name, 1, length (flv.meaning)) =
flv.meaning)
and substr (xle.name, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) )
= substr (flv.meaning, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) )) as REMIT_DETAILS,

(select to_char(flv.tag) from fnd_lookup_values flv


where flv.LANGUAGE = 'US'
and flv.lookup_type = 'IRM_DUNNING_REMITTANCE'
and nvl(enabled_flag,'Y')='Y'
and rownum <2
--Commented by Veda W4 and substr (xle.name, 1, length (flv.meaning)) =
flv.meaning)
and substr (xle.name, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) )
= substr (flv.meaning, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) ) ) as REMIT_EMAIL_DETAILS,
decode(ied.locale,'en-US',null,
(select to_char(flv.tag) from fnd_lookup_values flv
where flv.LANGUAGE = 'US'
and nvl(enabled_flag,'Y')='Y'
and rownum <2
and ied.locale <> 'en-US'
and flv.lookup_type = 'IRM_LATAM_REMITTANCE_CONTACT'
--Commented by Veda W4 and substr (xle.name, 1, length (flv.meaning)) =
flv.meaning) as
and substr (xle.name, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) )
= substr (flv.meaning, 1, decode(instr(flv.meaning,'_'),0,length
(flv.meaning),instr(flv.meaning,'_')-1) ))) LATAM_EMAIL,
hca.name,
(select distinct bu.name from HR_ORGANIZATION_UNITS_F_TL bu where
bu.ORGANIZATION_ID=:p_bu_id) BU
,ct.attribute9 Dispute_amount
--added by veda
,(select rctl.attribute8
from ra_customer_trx_lines_all rctl
where rctl.customer_trx_id = ct.customer_trx_id
and rctl.attribute8 is not null
and rownum <2
group by rctl.attribute8 ) faipo_num
,
(select trunc(rctl.attribute_date1)
from ra_customer_trx_lines_all rctl
where rctl.customer_trx_id = ct.customer_trx_id
and rctl.attribute_date1 is not null
and rownum <2
group by rctl.attribute_date1 ) faipo_date
FROM
iex_dunnings ied,
HZ_LOCATIONS LOC2,
hz_parties hp,
--AR_REMIT_TO_LOCS_ALL REMIT_LOC2,
iex_dunning_transactions idt,
ar_payment_schedules_all ar,
ra_customer_trx_all ct,
hz_cust_site_uses_all hcsa,
(select le.* ,hz.ADDR_ELEMENT_ATTRIBUTE2, hz.PROVINCE ,hz.county
from XLE_FIRSTPARTY_INFORMATION_V le,
HZ_LOCATIONS hz
where le.location_id = hz.location_id) xle,
--hz_cust_accounts hca,
(select hca.party_id, HCA.CUST_ACCOUNT_ID , hca.account_number , hou.name,
case when hca.attribute1 = US.meaning and hou.name = 'IM US BU'
then US.description
WHEN hou.name = 'IM CA BU'
then CA.description else null end as Location_id
from
hz_cust_accounts hca,
ar_payment_schedules_all arp,
ra_customer_trx_all rcta,
hr_operating_units hou,
(select LOOKUP_TYPE, LANGUAGE , to_char(meaning) as meaning , to_number(description
) as description from fnd_lookup_values
where LOOKUP_TYPE = 'AR_REMIT_ADDRESS_US' and
LANGUAGE = 'US' ) US,
(select LOOKUP_TYPE, LANGUAGE , to_char(meaning) as meaning , to_number(description
) as description from fnd_lookup_values
where LOOKUP_TYPE = 'AR_REMIT_ADDRESS_CA' and
LANGUAGE = 'US' ) CA
where
hca.attribute1 = US.meaning(+)
AND hou.name = CA.meaning(+)
AND arp.customer_id = HCA.CUST_ACCOUNT_ID
AND arp.customer_trx_id = rcta.customer_trx_id
AND rcta.org_id = hou.organization_id) hca,
fnd_territories_vl t2,
XLE_ENTITY_PROFILES xlep,
HZ_CUST_PROFILE_AMTS_F inte
,RA_TERMS_TL Ter
WHERE
ied.dunning_id = idt.dunning_id
and hp.party_id = hca.party_id
and idt.payment_schedule_id = ar.payment_schedule_id
and ar.customer_trx_id = ct.customer_trx_id
and ct.bill_to_site_use_id = hcsa.site_use_id
--and ct.remit_to_address_seq_id = REMIT_LOC2.ADDRESS_LOC_SEQ_ID
--and REMIT_LOC2.location_id = LOC2.location_id(+)
and HCA.location_id = LOC2.location_id(+)
and LOC2.country = t2.territory_code (+)
AND ar.customer_id = HCA.CUST_ACCOUNT_ID
AND ct.legal_entity_id = xle.legal_entity_id
--and inte.Site_use_id(+)=hcsa.Site_use_id
and hca.CUST_ACCOUNT_ID=inte.CUST_ACCOUNT_ID(+)
--and ct.attribute8 is null
AND (CASE WHEN ct.attribute8 is null then 'Yes'
ELSE (CASE WHEN ct.attribute12 is not null then 'Yes'
WHEN ct.attribute12 is null AND
(AR.AMOUNT_DUE_ORIGINAL>TO_NUMBER(ct.attribute9)) THEN 'Yes'
ELSE 'No' End) END)='Yes'
and ter.language='US'
and ar.term_id=ter.term_id(+)
and ct.creation_date <= To_date('28/02/2022','DD/MM/YYYY')
--order by 2,ar.due_date
and xlep.name=xle.name
)
order by original_due_date

You might also like