Skip to content
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

make time entries available per sow #188

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/controllers/analytics/time_entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
module Analytics
class TimeEntriesController < ApplicationController
before_action :set_project, only: %i[index]
before_action :set_statement_of_work, only: %i[index]

def index
@time_entries = Analytics::TimeEntriesAnalytics.new(@project, params[:start_date],
@time_entries = Analytics::TimeEntriesAnalytics.new(@project, @statement_of_work, params[:start_date],
params[:end_date]).data

render json: @time_entries
Expand All @@ -16,5 +17,9 @@ def index
def set_project
@project = Project.where(id: params[:project_id]).first
end

def set_statement_of_work
@statement_of_work = StatementOfWork.where(id: params[:statement_of_work_id]).first
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/statement_of_works_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class StatementOfWorksController < ApplicationController
before_action :set_project
before_action :set_project, only: %i[index create]
before_action :set_statement_of_work, only: %i[show update destroy]

def index
Expand Down Expand Up @@ -51,7 +51,7 @@ def set_project
end

def set_statement_of_work
@statement_of_work = @project.statement_of_works.find(params[:id])
@statement_of_work = StatementOfWork.find(params[:id])
end

def statement_of_work_params
Expand Down
12 changes: 7 additions & 5 deletions app/utils/analytics/time_entries_analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

module Analytics
class TimeEntriesAnalytics
def initialize(project, start_date, end_date)
def initialize(project, statement_of_work, start_date, end_date)
@project = project
@statement_of_work = statement_of_work
@start_date = start_date.to_datetime.beginning_of_day
@end_date = end_date.to_datetime.end_of_day
@worked_hours_cache = {} # Cache for memoization
Expand Down Expand Up @@ -83,12 +84,13 @@ def requirements

@requirements = if @project
Requirement.where(id: @project.statement_of_works.map(&:requirements)
.flatten.map(&:id)).active_in_period(
@start_date, @end_date
)
.flatten.map(&:id))
elsif @statement_of_work
Requirement.where(id: @statement_of_work.requirements.map(&:id))
else
Requirement.all.active_in_period(@start_date, @end_date)
Requirement.all
end
@requirements.active_in_period(@start_date, @end_date)
end

def clean_worked_hours(assignment)
Expand Down
Loading