Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions bin/reconcile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,26 @@ def send_email(address, subject, text)
mail.deliver
end

def send_imminent_unsubscribe_email(email, full_name, last_payment)
vars = {'name' => firstname(full_name),
'date' => last_payment.strftime('%Y-%m-%d')}
email_send_helper('../emails/imminent-lapse.erb', vars, email, "Your London Hackspace membership is about to lapse")
end

def send_unsubscribe_email(email, full_name, last_payment)
vars = {'name' => firstname(full_name),
'date' => last_payment.strftime('%Y-%m-%d')}
template = Erubis::Eruby.new(File.read('../emails/lapse.erb'))
send_email(email, "Your London Hackspace membership has lapsed", template.result(vars))
email_send_helper('../emails/lapse.erb', vars, email, "Your London Hackspace membership has lapsed")
end

def send_subscribe_email(email, full_name)
vars = {'name' => firstname(full_name)}
template = Erubis::Eruby.new(File.read('../emails/subscribe.erb'))
send_email(email, "Your London Hackspace membership is now active", template.result(vars))
email_send_helper('../emails/subscribe.erb', vars, email, "Your London Hackspace membership is now active")
end

def email_send_helper(filename, vars, email, subject)
template = Erubis::Eruby.new(File.read(filename))
send_email(email, subject, template.result(vars))
end

ofx = OfxParser::OfxParser.parse(open(ARGV[0]))
Expand Down Expand Up @@ -92,6 +101,7 @@ def send_subscribe_email(email, full_name)
end
end

# Email people who have been unsubscribed.
db.execute("SELECT users.*, (SELECT max(timestamp) FROM transactions WHERE user_id = users.id) AS lastsubscription
FROM users WHERE users.subscribed = 1 AND lastsubscription < date('now', '-1 month', '-14 days')") do |user|

Expand All @@ -104,3 +114,17 @@ def send_subscribe_email(email, full_name)
system("/var/www/hackspace-foundation-sites/bin/ldap-delete.sh", user['ldapuser'])
end
end

# Email people who are about to be unsubscribed.
db.execute("SELECT users.*, (SELECT max(timestamp) FROM transactions WHERE user_id = users.id) AS lastsubscription
FROM users
WHERE users.subscribed = 1
AND lastsubscription < date('now', '-1 month', '-10 days')
AND (lapsing_membership_reminder_timestamp IS NULL
OR lapsing_membership_reminder_timestamp < date('now', '-1 month'))") do |user|

puts "Warning #{user['full_name']} about imminent subscription lapse."
db.execute("UPDATE users SET lapsing_membership_reminder_timestamp = date('now') WHERE id = ?", user['id'])
send_imminent_unsubscribe_email(user['email'], user['full_name'], Time.iso8601(user['lastsubscription']))
end

32 changes: 32 additions & 0 deletions emails/imminent-lapse.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Dear <%=name%>,

This is an automated email sent from the Hackspace payment system.

Our records show no membership payments from you in over a month. As a
result, your membership will be suspended automatically if you don't
make a payment within the next two days.

We last received a payment from you on <%=date%>.

If you believe this is a mistake, please reply to this email with the
date, amount, and reference of your most recent payment, and we'll look
into it.

If you've changed bank account or want to confirm our payment details
and your reference you can find them on our web site:

https://london.hackspace.org.uk/members/

Alternatively if you are cancelling your membership we'd be very
interested to hear any feedback you have about why you've cancelled your
membership, or how we can improve London Hackspace - just hit reply and
let us know.

If you're still storing anything in the space, please arrange to remove
it as soon as possible, otherwise we will have to dispose of it to free
up space for other members to use.

Thanks,

The London Hackspace trustees
trustees@london.hackspace.org.uk
1 change: 1 addition & 0 deletions etc/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CREATE TABLE "users" (
has_profile BOOLEAN NOT NULL DEFAULT 0,
disabled_profile BOOLEAN NOT NULL DEFAULT 0,
doorbot_timestamp DATETIME,
lapsing_membership_reminder_timestamp DATETIME,
emergency_name VARCHAR(255),
emergency_phone VARCHAR(40),
ldapuser VARCHAR(32) UNIQUE,
Expand Down
Binary file modified london.hackspace.org.uk/organisation/docs/articles.pdf
Binary file not shown.