Skip to content

Instantly share code, notes, and snippets.

@iMagesh
Created February 24, 2012 09:54
Show Gist options
  • Save iMagesh/1899866 to your computer and use it in GitHub Desktop.
Save iMagesh/1899866 to your computer and use it in GitHub Desktop.
Weekly report task to managers about the project timeline
task :weekly_report => [:environment] do
@start_date=Date.today.beginning_of_week
start_date=@start_date.to_date
@end_date=6.days.since(@start_date)
end_date=@end_date.to_date
@project=Project.find_all_by_isactive(true)
@proj=[]
@project.each do |project|
@proj << {:name => project.projectname,:billable => project.timeentries.sum(:hours_taken, :conditions=>['DATE(task_date)>=? and DATE(task_date)<=? and status=?',start_date,end_date, "Billable"]),:nonbillable => project.timeentries.sum(:hours_taken, :conditions=>['DATE(task_date)>=? and DATE(task_date)<=? and status=?',start_date,end_date, "NonBillable"]) ,:hours =>project.timeentries.sum(:hours_taken, :conditions=>['DATE(task_date)>=? and DATE(task_date)<=?',start_date,end_date])}
end
UserNotifier.deliver_weekly_report_project(@proj)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment