Skip to content

Commit

Permalink
feat: added current month to customer effort hours data
Browse files Browse the repository at this point in the history
  • Loading branch information
celsoMartins committed Nov 12, 2024
1 parent fdc7b04 commit a6429fc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ def index
def show
@customers = [@customer]

@customer_consolidations = @customer.customer_consolidations.monthly_data.order(:consolidation_date)
@customer_consolidations = build_customer_consolidations(@customer)
@unscored_demands = @customer.exclusives_demands.unscored_demands.order(external_id: :asc)
@demands_blocks = @customer.demand_blocks.active.order(block_time: :asc)
@user_invite = UserInvite.new(invite_object_id: @customer.id, invite_type: :customer)
@contracts = @customer.contracts.includes([:product]).order(end_date: :desc)
@contract = Contract.new(customer: @customer)

build_pressure_and_speed
end

Expand Down Expand Up @@ -79,6 +80,11 @@ def update_cache

private

def build_customer_consolidations(customer)
customer_last_data_point = customer.customer_consolidations.order(:consolidation_date).last
customer.customer_consolidations.monthly_data.or(customer.customer_consolidations.where(id: customer_last_data_point.id)).distinct.order(:consolidation_date)
end

def build_pressure_and_speed
@flow_pressure = @customer_consolidations.last&.flow_pressure || @customer.total_flow_pressure
@average_speed = DemandService.instance.average_speed(@customer.exclusives_demands)
Expand Down

0 comments on commit a6429fc

Please sign in to comment.