Show logged time on jobs

This commit is contained in:
Trevor Vallender 2023-11-21 14:37:11 +00:00
parent 73d3066b74
commit 1d4744f108
3 changed files with 14 additions and 4 deletions

View File

@ -8,7 +8,13 @@ class Job < ActiveRecord::Base
scope :project, ->(project) { where(project_id: project.id) } scope :project, ->(project) { where(project_id: project.id) }
def time_logged def total_time_logged
42 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)
end end
end end

View File

@ -20,9 +20,7 @@
<%= f.date_field :ends_on %> <%= f.date_field :ends_on %>
</p> </p>
<p>
<%= f.hidden_field :project_id, value: @project.id %> <%= f.hidden_field :project_id, value: @project.id %>
</p>
<p> <p>
<%= f.label :external_project_id %> <%= f.label :external_project_id %>

View File

@ -6,6 +6,12 @@
<dd><%= @job.starts_on %></dd> <dd><%= @job.starts_on %></dd>
<dt>Ends on:</dt> <dt>Ends on:</dt>
<dd><%= @job.ends_on %></dd> <dd><%= @job.ends_on %></dd>
<dt>Total time logged:</dt>
<dd><%= @job.total_time_logged %></dd>
<% TimeEntryActivity.all.each do |activity| %>
<dt>Total time logged for <%= activity.name %></dt>
<dd><%= @job.total_time_logged_for(activity) %></dd>
<% end %>
</dl> </dl>
<%= link_to 'Edit job', edit_job_path(@job, project_id: @project.id) %> <%= link_to 'Edit job', edit_job_path(@job, project_id: @project.id) %>