Browse Source

fix calc

main
Christoph Marzell 1 month ago
parent
commit
d250915f90
  1. 15
      app/controllers/entries_controller.rb

15
app/controllers/entries_controller.rb

@ -132,11 +132,20 @@ class EntriesController < ApplicationController
else
relevant_entries = entries
end
first_entry_date = entries.first.date
# Gruppiere nach Kalenderjahr + Woche
active_weeks = relevant_entries.group_by { |e| [e.date.cwyear, e.date.cweek] }.keys.size
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
else
# Sonst bis heute rechnen
total_days = (Date.today - first_entry_date).to_i
end
weeks = total_days / 7.0
weeks = 1 if weeks < 1
weeks = [active_weeks, 1].max
actual_per_week = (done_minutes / 60.0) / weeks
@actual_hours_per_week[[typ, art]] = actual_per_week.round(2)

Loading…
Cancel
Save