Skip to content

Commit

Permalink
add contract hours to all contract models
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Jul 2, 2024
1 parent 889e24c commit 408c5b2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
11 changes: 11 additions & 0 deletions app/models/concerns/calculable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
module Calculable
extend ActiveSupport::Concern

def contract_total_hours
raise NotImplementedError
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_hours(assignment, start_date, end_date, include_paid_time_off = false)
hours = Analytics::TimeEntries::ExpectedHours.new(assignment, start_date, end_date).data
return hours if include_paid_time_off
Expand Down
4 changes: 4 additions & 0 deletions app/models/fixed_bid_contract_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class FixedBidContractModel < ApplicationRecord

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

def contract_total_hours
consumed_hours
end

def assignment_executed_income(_assignment, _start_date, _end_date)
0
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/maintenance_contract_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class MaintenanceContractModel < ApplicationRecord

validates :delivery_period, inclusion: { in: %w[weekly monthly] }

def contract_total_hours
expected_hours(nil, statement_of_work.start_date.to_date, statement_of_work.end_date.to_date)
end

def expected_hours(_assignment, start_date, end_date, _include_paid_time_off = false)
if delivery_period == 'weekly'
expected_hours_per_period * weeks_in_period(start_date, end_date)
Expand Down
7 changes: 0 additions & 7 deletions app/models/retainer_contract_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ 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
Expand Down
4 changes: 4 additions & 0 deletions app/models/time_and_materials_contract_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class TimeAndMaterialsContractModel < ApplicationRecord

validates :limit_by, inclusion: { in: %w[hours contract_size] }

def contract_total_hours
hours_amount
end

def assignment_executed_income(assignment, start_date, end_date)
hours = worked_hours(assignment, start_date, end_date)
hours * (hourly_price || 0)
Expand Down

0 comments on commit 408c5b2

Please sign in to comment.