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

fix calculations for the statements of work #138

Merged
merged 1 commit into from
Dec 13, 2023
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
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-12-13 21:43:07 UTC using RuboCop version 1.56.2.
# on 2023-12-13 23:04:46 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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 5
# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 29
Max: 34

# Offense count: 5
# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 19
Max: 23

# Offense count: 1
# Configuration parameters: AllowedMethods.
Expand Down
15 changes: 10 additions & 5 deletions app/controllers/analytics/finances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
module Analytics
class FinancesController < ApplicationController
before_action :set_project, only: %i[index]
before_action :set_statement_of_works, only: %i[index]

def index
@finances = if @project
Analytics::Finances::Models::FinancialStatementsOfWork.new(@project, start_date, end_date)
else
Analytics::Finances::Models::FinancialProjects.new(start_date, end_date)
end
@finances = Analytics::Finances::Models::FinancialStatementsOfWork.new(@statement_of_works, start_date, end_date,
false)
@finances.financial_items = @finances.financial_items.sort_by(&:name)
end

private

def set_statement_of_works
@statement_of_works = @project.statement_of_works.active_in_period(start_date, end_date) if @project

@statement_of_works = StatementOfWork.active_in_period(start_date, end_date)
end

def set_project
@project = Project.where(id: params[:project_id]).first
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def add_executed_income(income)
income_to_add = 0
if (@total_executed_income + income + @executed_income_to_start_date) >= income_limit
income_to_add = [income_limit - @total_executed_income - @executed_income_to_start_date, 0].max
@total_executed_income = income_limit

@total_executed_income = income_to_add
else
income_to_add = income
@total_executed_income += income
Expand All @@ -34,7 +35,7 @@ def add_executed_income(income)
def add_expected_income(income)
if @total_expected_income + income + @executed_income_to_start_date > income_limit
income_to_add = [income_limit - @total_expected_income - @executed_income_to_start_date, 0].max
@total_expected_income = income_limit
@total_expected_income = income_to_add
else
income_to_add = income
@total_expected_income += income
Expand Down
32 changes: 0 additions & 32 deletions app/utils/analytics/finances/models/financial_projects.rb

This file was deleted.

10 changes: 5 additions & 5 deletions app/utils/analytics/finances/models/financial_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module Analytics
module Finances
module Models
class FinancialReport
attr_reader :total_executed_income,
:total_expected_income,
:total_executed_cost,
:total_expected_cost,
:financial_items
attr_accessor :total_executed_income,
:total_expected_income,
:total_executed_cost,
:total_expected_cost,
:financial_items

def initialize(start_date, end_date)
@total_executed_income = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ module Analytics
module Finances
module Models
class FinancialStatementsOfWork < FinancialReport
def initialize(project, start_date, end_date, resource_level = true)
@project = project
def initialize(statement_of_works, start_date, end_date, resource_level = true)
@statement_of_works = statement_of_works

@resource_level = resource_level
super(start_date, end_date)
end

def calculate!
@project.statement_of_works.active_in_period(@start_date, @end_date).each do |statement_of_work|
@statement_of_works.each do |statement_of_work|
statement_of_work_start_date = statement_of_work.start_date.to_datetime

executed_income_to_start_date = 0
Expand All @@ -32,6 +33,12 @@ def calculate!
name = financial_item_name(financial_item, statement_of_work)
existing_item = financial_item_by_name(name, financial_item.slug)
existing_item.merge(financial_item)

next if @resource_level

existing_item.executed_income = model_calculator.total_executed_income
existing_item.expected_income = model_calculator.total_expected_income
existing_item.slug = statement_of_work.project.slug
end
end
end
Expand Down
Loading