Skip to content

Instantly share code, notes, and snippets.

@andyh
Forked from anonymous/hospitalbooking_controller.rb
Last active December 15, 2015 16:58
Show Gist options
  • Save andyh/5292591 to your computer and use it in GitHub Desktop.
Save andyh/5292591 to your computer and use it in GitHub Desktop.
class HospitalBooking
def self.send_overtime_mail(user, bookings)
OvertimeMailer.overtime_pdf(user, hospital_booking).deliver
end
end
def index
@hospital_bookings = HospitalBooking.scoped
if params[:format] == 'pdf'
@hospital_bookings = @hospital_bookings.where(:day => Date.today.beginning_of_month..Date.today.end_of_month)
HospitalBooking.send_overtime_mail(current_user, @hospital_bookings)
end
respond_to do |format|
format.html
format.pdf do
render :pdf => "#{Date.today.strftime('%B')} Overtime Report",
:header => {:html => {:template => 'layouts/pdf.html.erb'}}
end
end
end
task :overtime_report => :environment do
if Date.today.day == 18
user = User.where(:role => :administrator).first
bookings = HospitalBooking.where(:day => Date.today.beginning_of_month..Date.today.end_of_month)
HospitalBooking.send_overtime_mail(user, bookings)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment