From 08227691137d4da1f36a02690ff89a3899abe468 Mon Sep 17 00:00:00 2001 From: Christoph Marzell Date: Wed, 15 Jul 2026 05:59:46 +0200 Subject: [PATCH] fix display --- app/controllers/entries_controller.rb | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index 26ba2e0..d5d8837 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb @@ -5,15 +5,17 @@ class EntriesController < ApplicationController def index @entries = current_user.entries.order(date: :desc) - # Nur Einträge bis einschließlich heute für Zeitberechnungen verwenden + # Für Berechnungen nur Einträge bis einschließlich heute verwenden. + # Keine Sortierung setzen, da diese Relation später unterschiedlich + # ausgewertet wird. @calculation_entries = current_user.entries .where("date <= ?", Date.current) - .order(date: :desc) @running_entry = current_user.entries.find_by( end_time: nil, beschreibung: "Timer" ) + required_hours_matrix = current_user.required_hours_matrix.to_h weekly_target_matrix = current_user.weekly_target_matrix.to_h @@ -307,15 +309,17 @@ class EntriesController < ApplicationController .where( "COALESCE(hours, 0) > 0 OR COALESCE(minutes, 0) > 0" ) - .order(:date) - .to_a - next if entries.empty? + next unless entries.exists? - spent_minutes = sum_minutes(entries) + spent_minutes = entries.sum do |entry| + entry.hours.to_i * 60 + entry.minutes.to_i + end + + first_entry_date = entries.minimum(:date) + last_entry_date = entries.maximum(:date) - first_entry_date = entries.first.date - last_entry_date = entries.last.date + next unless first_entry_date required_minutes = (required_hours * 60).round completed = spent_minutes >= required_minutes @@ -332,11 +336,11 @@ class EntriesController < ApplicationController weeks = total_days / 7.0 - actual_hours = spent_minutes / 60.0 + actual_hours_per_week = + (spent_minutes / 60.0) / weeks - @actual_hours_per_week[[typ, art]] = ( - actual_hours / weeks - ).round(2) + @actual_hours_per_week[[typ, art]] = + actual_hours_per_week.round(2) end end