Old Dunning Letter DM Code
Old Dunning Letter DM Code
(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,