Skip to content

Commit

Permalink
make time entries available per sow
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Mar 14, 2024
1 parent b0b0752 commit 76926ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
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

0 comments on commit 76926ff

Please sign in to comment.