What it does
Anchors on the cash_ledger activation record (desc codes
The
57109 or 57110) to find customers whose card was activated on the open business day that is nDays back from today.The
roadAssist flag filters the candidate set by RSA status. The gotRSA field is an empty string for customers without RSA, so the message template works without branching. Same for gotRewardsURL when the shop has no rewards URL configured in sms_tags.
CTEs
shopSchedule
Open/closed by day of week
From config_client_location_hours
dateSteps / collectDate
Backward date walk to activation target
Counts open days only. collectDate is the resolved match date for cash_ledger created_at.
rewardsBalance
Current balance per customer
credits − debits, familyID scoped, deleted_at excluded
rewardsURL / rsaPhone / warrantyPhone
Shop-level dynamic content tags
Pulled from sms_tags by tag_name. Used to build gotRewardsURL and gotRSA output fields.
mainQuery
Candidate selection with dedup
Anchors on cash_ledgers. roadAssist case applied in where. Dedup by customer_id (SMS) or email (Email).
Output fields
candidateID
companyID
"Company"
"Name"
"FirstName"
last_name
"FullName"
"Email"
"CustPhone"
"RewardsCard"
"RewardsBalance"
"RewardsPercentage"
"RSA"
"AwardName"
"gotRSA"
"gotRewardsURL"
"ActivationDate"