Skip to content

Commit

Permalink
add project progress controller
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Jul 1, 2024
1 parent ca067cc commit 4a9858c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-06-05 18:08:13 UTC using RuboCop version 1.56.2.
# on 2024-07-01 18:59:17 UTC using RuboCop version 1.56.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -21,7 +21,7 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 26
Max: 27

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand Down Expand Up @@ -63,7 +63,7 @@ Style/OptionalBooleanParameter:
- 'app/models/retainer_contract_model.rb'
- 'app/utils/analytics/finances/models/financial_statements_of_work.rb'

# Offense count: 11
# Offense count: 12
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
25 changes: 25 additions & 0 deletions app/controllers/analytics/project_progress_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Analytics
class ProjectProgressController < ApplicationController
before_action :set_project, only: %i[index]
before_action :set_statement_of_work, only: %i[index]

def index
render json: {
contract_hours: @statement_of_work.contract_model.contract_total_hours,
consumed_hours: @statement_of_work.contract_model.consumed_hours
}
end

private

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
13 changes: 12 additions & 1 deletion app/models/retainer_contract_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@ class RetainerContractModel < ApplicationRecord

has_one :statement_of_work, as: :contract_model, dependent: :destroy

def contract_total_hours
expected_hours_per_period * months_in_period(statement_of_work.start_date, statement_of_work.end_date)
end

def consumed_hours
assignments = statement_of_work.requirements.map(&:assignments).flatten
assignments.sum do |assignment|
worked_hours(assignment, statement_of_work.start_date, statement_of_work.end_date)
end
end

def expected_income(start_date, end_date)
revenue_per_period * months_in_period(start_date, end_date)
end

def months_in_period(start_date, end_date)
return 1 if start_date.month == end_date.month && start_date.year == end_date.year

((end_date.year * 12) + end_date.month) - ((start_date.year * 12) + start_date.month)
((end_date.year * 12) + end_date.month) - ((start_date.year * 12) + start_date.month) + 1
end

def assignment_executed_income(_assignment, _start_date, _end_date)
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
namespace :analytics do
resources :time_entries, only: [:index]
resources :finances, only: [:index]
resources :project_progress, only: [:index]
end

resources :users
Expand Down

0 comments on commit 4a9858c

Please sign in to comment.