diff --git a/bin/reconcile.rb b/bin/reconcile.rb index b4ee4b24..2ae28d44 100755 --- a/bin/reconcile.rb +++ b/bin/reconcile.rb @@ -23,6 +23,13 @@ def send_email(address, subject, text) mail.deliver end +def send_lapse_warning_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_warning.erb')) + send_email(email, "Your London Hackspace membership wilk lapse in 7 days", template.result(vars)) +end + def send_unsubscribe_email(email, full_name, last_payment) vars = {'name' => firstname(full_name), 'date' => last_payment.strftime('%Y-%m-%d')} @@ -97,6 +104,19 @@ def send_subscribe_email(email, full_name) end end +db.exec("SELECT users.*, (SELECT max(timestamp) FROM transactions WHERE user_id = users.id) AS lastsubscription + FROM users + WHERE users.subscribed = true + AND (SELECT max(timestamp) FROM transactions WHERE user_id = users.id) < now() - interval '1 month' - interval '7 days' + AND (SELECT max(timestamp) FROM transactions WHERE user_id = users.id) > now() - interval '1 month' - interval '8 days'" + ) do |result| + + result.each do |user| + puts "Warning #{user['full_name']} of membership soon to lapse" + send_lapse_warning_email(user['email'], user['full_name'], Time.parse(user['lastsubscription'])) + end +end + db.exec("SELECT users.*, (SELECT max(timestamp) FROM transactions WHERE user_id = users.id) AS lastsubscription FROM users WHERE users.subscribed = true diff --git a/emails/lapse_warning.erb b/emails/lapse_warning.erb new file mode 100644 index 00000000..51da3468 --- /dev/null +++ b/emails/lapse_warning.erb @@ -0,0 +1,32 @@ +Dear <%=name%>, + +This is an automated email sent from our payment system. + +We haven't noticed a payment from you in over a month, and if we +do not within 7 days your membership will be automatically suspended, and your +door access will be disabled. + +We last received a payment from you on <%=date%>. + +If you believe we are warning you in error, 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