2023-11-22 19:44:13 +00:00
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
|
2023-11-16 20:23:09 +00:00
|
|
|
class Job < ActiveRecord::Base
|
|
|
|
validates :starts_on,
|
|
|
|
:ends_on,
|
|
|
|
:name,
|
|
|
|
presence: true
|
|
|
|
|
2023-11-21 14:09:51 +00:00
|
|
|
belongs_to :project
|
2023-11-22 19:44:13 +00:00
|
|
|
has_many :time_entries
|
2023-11-21 14:09:51 +00:00
|
|
|
|
2023-11-21 13:59:43 +00:00
|
|
|
scope :project, ->(project) { where(project_id: project.id) }
|
|
|
|
|
2023-11-21 14:37:11 +00:00
|
|
|
def total_time_logged
|
|
|
|
TimeEntry.where(job_id: id)
|
|
|
|
.sum(:hours)
|
|
|
|
end
|
|
|
|
|
|
|
|
def total_time_logged_for(activity)
|
|
|
|
TimeEntry.where(job_id: id, activity_id: activity.id)
|
|
|
|
.sum(:hours)
|
2023-11-16 20:23:09 +00:00
|
|
|
end
|
2023-11-22 19:44:13 +00:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
ActionView::Base.send(:include, Rails.application.routes.url_helpers)
|
|
|
|
ActionController::Base.helpers.link_to name, ActionController::Base.helpers.job_path(self, project_id: project.id)
|
|
|
|
end
|
2023-11-16 20:23:09 +00:00
|
|
|
end
|