Here's a sql query we run daily, which will set a customer to inactive if they have no services, domains, open invoices, and are not affiliates. You can change 'Inactive' to 'Closed'.
update tblclients c
set status = 'Inactive'
where status = 'Active'
and not exists (select 1 from tblhosting where userid = c.id and domainstatus in ('Active', 'Pending', 'Suspended'))
and not exists (select 1 from tbldomains where userid = c.id and status in ('Active', 'Pending', 'Pending Transfer'))
and not exists (select 1 from tblinvoices where userid = c.id and status = 'Unpaid')
and not exists (select 1 from tblaffiliates where clientid = c.id);