-
-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weekly supervisor digest mailer #1346
Changes from all commits
c0c664b
58e7983
818f43d
5e60b6f
e963514
fa675eb
384c951
c8c3745
ae66a5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,20 @@ def case_contacts_ordered_by_occurred_at | |
object.case_contacts.sort_by(&:occurred_at) | ||
end | ||
|
||
def case_contacts_latest | ||
object.case_contacts.max_by(&:occurred_at) | ||
end | ||
|
||
def successful_contacts_this_week | ||
this_week = Date.today - 7.days..Date.today | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we already had something like this somewhere... I want to have all this logic in one central place. I will take a look around. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like it if we could split out a helper or something(?) to hold all our date-related logic like this Existing in user:
|
||
object.case_contacts.where(occurred_at: this_week).where(contact_made: true).count | ||
end | ||
|
||
def unsuccessful_contacts_this_week | ||
this_week = Date.today - 7.days..Date.today | ||
object.case_contacts.where(occurred_at: this_week).where(contact_made: false).count | ||
end | ||
|
||
def court_report_select_option | ||
[ | ||
"#{object.case_number} - #{object.has_transitioned? ? "transition" : "non-transition"}", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class SupervisorMailer < ApplicationMailer | ||
default from: "CASA Admin <no-reply@casa-r4g-staging.herokuapp.com>" | ||
|
||
def weekly_digest(supervisor) | ||
@supervisor = supervisor | ||
mail(to: @supervisor.email, subject: "Weekly summary of volunteer's activities for the weeek of #{Date.today - 7.days}") | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<meta itemprop="name" content="Court Report Due Reminder Email" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> | ||
<table width="100%" cellpadding="0" cellspacing="0" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> | ||
<tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> | ||
<td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top"> | ||
<%= @supervisor.display_name %>, | ||
</td> | ||
</tr> | ||
<tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; margin: 0;"> | ||
<td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 16px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top"> | ||
Here's a summary of what happened with your volunteers this last week. | ||
</td> | ||
</tr> | ||
<% @supervisor.volunteers.each do |volunteer| %> | ||
|
||
<% volunteer.case_assignments_with_cases.each do |case_assignment| %> | ||
<% casa_case = case_assignment.casa_case %> | ||
<tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0; text-align: left;"> | ||
<td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top"> | ||
<b><%= "Summary for #{volunteer.display_name} Case #{casa_case.case_number}" %></b> | ||
<br> | ||
<% successful_contacts = casa_case.decorate.successful_contacts_this_week %> | ||
<% unsuccessful_contacts = casa_case.decorate.unsuccessful_contacts_this_week %> | ||
<% if successful_contacts + unsuccessful_contacts > 0 %> | ||
<%= "Number of succesful case contacts made this week: #{successful_contacts}" %> | ||
<br> | ||
<%= "Number of unsuccesful case contacts made this week: #{unsuccessful_contacts} " %> | ||
<br> | ||
<% recent_contact = casa_case.decorate.case_contacts_latest %> | ||
<%= "Most recent contact attempted:" %> | ||
<br> | ||
<%= " - Date: #{recent_contact&.occurred_at&.strftime("%B %e, %Y")}" %> | ||
<br> | ||
<%= " - Type: #{recent_contact&.decorate.contact_types}" %> | ||
<br> | ||
<%= " - Duration: #{recent_contact&.duration_minutes}" %> | ||
<br> | ||
<%= " - Contact Made: #{recent_contact&.contact_made}" %> | ||
<br> | ||
<%= " - Medium Type: #{recent_contact&.medium_type}" %> | ||
<br> | ||
<%= " - Notes: #{recent_contact&.notes}" %> | ||
<% else %> | ||
No contact attempts for this week. | ||
<% end %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
<% end %> | ||
</table> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Preview all emails at http://localhost:3000/rails/mailers/supervisor_mailer | ||
# :nocov: | ||
class SupervisorMailerPreview < ActionMailer::Preview | ||
def weekly_digest | ||
SupervisorMailer.weekly_digest(User.last) | ||
end | ||
end | ||
# :nocov: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
desc "Send an email to supervisors each week to share an overview of their volunteers' activities" | ||
task send_supervisor_digest: :environment do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need a cron for this or similar- I assume heroku has something for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote a mailer for reminders when court reports are due. I believe I was told to create a task that would be run by heroku. I never followed up about that to see if that was scheduled. I would assume heroku has something for that, but I'm not super familiar. I can look it up and try to set that up once this gets merged so we can set it up for this one and the court report reminder. |
||
Supervisor.each do |supervisor| | ||
SupervisorMailer.weekly_digest(supervisor) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a scope on the model, to avoid having to pull all the case contacts every time.