Browse Source

fix display

main
Christoph Marzell 4 weeks ago
parent
commit
fa0155c806
  1. 54
      app/controllers/entries_controller.rb

54
app/controllers/entries_controller.rb

@ -94,8 +94,8 @@ class EntriesController < ApplicationController
.where(praktikums_typ: typ, entry_art: art)
.maximum(:date)
start_date = [last_entry_date, Date.today].compact.max
#start_date = [last_entry_date, Date.today].compact.max
start_date = Date.today
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
@ -109,47 +109,45 @@ class EntriesController < ApplicationController
@actual_hours_per_week = {}
User::PRAKTIKUMSTYPEN.product(User::ENTRY_ARTEN).each do |typ, art|
total_req_hours = current_user.required_hours_matrix.to_h.dig(typ, art).to_f
next if total_req_hours <= 0
required_hours = current_user.required_hours_matrix
.to_h
.dig(typ, art)
.to_f
total_req_minutes = (total_req_hours * 60).to_i
next unless required_hours.positive?
entries = current_user.entries
entries = @calculation_entries
.where(praktikums_typ: typ, entry_art: art)
.where(
"COALESCE(hours, 0) > 0 OR COALESCE(minutes, 0) > 0"
)
.order(:date)
next if entries.empty?
remaining = @remaining_minutes_matrix.dig(typ, art).to_i
done_minutes = [total_req_minutes - remaining, 0].max
# Wenn alles erledigt: nur bis zum letzten Eintrag mit Stunden
if remaining == 0 && done_minutes > 0
last_effort_entry = entries.select { |e|
((e.hours.to_i * 60) + e.minutes.to_i) > 0
}.last
relevant_entries = entries.select { |e| e.date <= last_effort_entry.date }
else
relevant_entries = entries
spent_minutes = entries.sum do |entry|
entry.hours.to_i * 60 + entry.minutes.to_i
end
first_entry_date = entries.first.date
if remaining == 0 && done_minutes > 0
# Wenn abgeschlossen → bis zum letzten Eintrag rechnen
last_entry_date = entries.maximum(:date)
total_days = (last_entry_date - first_entry_date).to_i
required_minutes = (required_hours * 60).to_i
completed = spent_minutes >= required_minutes
period_end =
if completed
entries.last.date
else
# Sonst bis heute rechnen
total_days = (Date.today - first_entry_date).to_i
Date.current
end
weeks = total_days / 7.0
weeks = 1 if weeks < 1
total_days = (period_end - first_entry_date).to_i + 1
total_days = 7 if total_days < 7
actual_per_week = (done_minutes / 60.0) / weeks
weeks = total_days / 7.0
@actual_hours_per_week[[typ, art]] = actual_per_week.round(2)
@actual_hours_per_week[[typ, art]] =
((spent_minutes / 60.0) / weeks).round(2)
end

Loading…
Cancel
Save