diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index 26046f3..caa1451 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb @@ -80,21 +80,31 @@ class EntriesController < ApplicationController # Voraussichtliches Ende je Kombination basierend auf weekly_target_matrix # @estimated_end_by_typ_art = {} + + @remaining_minutes_matrix.each do |typ, arts| @estimated_end_by_typ_art[typ] ||= {} arts.each do |art, remaining_minutes| hours_remaining = remaining_minutes / 60.0 weekly_hours = current_user.weekly_target_matrix.dig(typ, art).to_f - if weekly_hours > 0 - weeks_remaining = (hours_remaining / weekly_hours).ceil - @estimated_end_by_typ_art[typ][art] = Date.today + weeks_remaining.weeks + + last_entry_date = current_user.entries + .where(praktikums_typ: typ, entry_art: art) + .maximum(:date) + + start_date = [last_entry_date, Date.today].compact.max + + if weekly_hours > 0 && hours_remaining > 0 + weeks_remaining = (hours_remaining / weekly_hours).ceil + @estimated_end_by_typ_art[typ][art] = start_date + weeks_remaining.weeks else @estimated_end_by_typ_art[typ][art] = nil end end end + @actual_hours_per_week = {} User::PRAKTIKUMSTYPEN.product(User::ENTRY_ARTEN).each do |typ, art| diff --git a/app/views/entries/index.html.erb b/app/views/entries/index.html.erb index 0045cea..82efce5 100644 --- a/app/views/entries/index.html.erb +++ b/app/views/entries/index.html.erb @@ -41,6 +41,7 @@ <% spent = @spent_minutes_matrix.dig(typ, art) %> <% next if spent.blank? %> <% soll = current_user.required_hours_matrix.dig(typ, art) %> + <% next if soll.blank? %> <% weekly = current_user.weekly_target_matrix.dig(typ, art) %> <% ende = @estimated_end_by_typ_art.dig(typ, art) %>