diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index 57f17dc..f2a1f7a 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb @@ -22,6 +22,10 @@ class EntriesController < ApplicationController end end + @completion_percent_by_typ_art = {} + + + # Verbleibende Minuten je Kombination @remaining_minutes_matrix = {} @time_by_typ_art.each do |typ, arts| @@ -34,6 +38,26 @@ class EntriesController < ApplicationController end end + User::PRAKTIKUMSTYPEN.product(User::ENTRY_ARTEN).each do |typ, art| + total_required = current_user.required_hours_matrix.to_h.dig(typ, art).to_f + remaining_minutes = @remaining_minutes_matrix.dig(typ, art).to_i + required_minutes = (total_required * 60).to_i + entries_exist = current_user.entries.where(praktikums_typ: typ, entry_art: art).exists? + + Rails.logger.info "=== #{art} #{typ} ===" + Rails.logger.info "Erforderlich (min): #{required_minutes}, Verbleibend: #{remaining_minutes}, Einträge vorhanden? #{entries_exist}" + + if total_required > 0 && entries_exist + done_minutes = required_minutes - remaining_minutes + percent = (done_minutes / required_minutes.to_f * 100).round + percent = 100 if percent > 100 + @completion_percent_by_typ_art[[typ, art]] = percent + else + @completion_percent_by_typ_art[[typ, art]] = 0 + end + end + + @total_kilometer_costs_by_year = Entry.total_kilometer_cost_by_year(current_user) @fortbildungskosten_by_year = Entry.total_fortbildungskosten_by_year(current_user) @selbstsupervision_by_year = Entry.total_supervision_by_year(current_user) diff --git a/app/views/entries/index.html.erb b/app/views/entries/index.html.erb index 3bc9878..9ea1797 100644 --- a/app/views/entries/index.html.erb +++ b/app/views/entries/index.html.erb @@ -77,6 +77,7 @@