Browse Source

fix display

main
Christoph Marzell 4 weeks ago
parent
commit
0822769113
  1. 28
      app/controllers/entries_controller.rb

28
app/controllers/entries_controller.rb

@ -5,16 +5,18 @@ class EntriesController < ApplicationController
def index def index
@entries = current_user.entries.order(date: :desc) @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 @calculation_entries = current_user.entries
.where("date <= ?", Date.current) .where("date <= ?", Date.current)
.order(date: :desc)
@running_entry = current_user.entries.find_by( @running_entry = current_user.entries.find_by(
end_time: nil, end_time: nil,
beschreibung: "Timer" beschreibung: "Timer"
) )
required_hours_matrix = current_user.required_hours_matrix.to_h required_hours_matrix = current_user.required_hours_matrix.to_h
weekly_target_matrix = current_user.weekly_target_matrix.to_h weekly_target_matrix = current_user.weekly_target_matrix.to_h
@ -307,15 +309,17 @@ class EntriesController < ApplicationController
.where( .where(
"COALESCE(hours, 0) > 0 OR COALESCE(minutes, 0) > 0" "COALESCE(hours, 0) > 0 OR COALESCE(minutes, 0) > 0"
) )
.order(:date)
.to_a
next if entries.empty?
next unless entries.exists?
spent_minutes = entries.sum do |entry|
entry.hours.to_i * 60 + entry.minutes.to_i
end
spent_minutes = sum_minutes(entries)
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 required_minutes = (required_hours * 60).round
completed = spent_minutes >= required_minutes completed = spent_minutes >= required_minutes
@ -332,11 +336,11 @@ class EntriesController < ApplicationController
weeks = total_days / 7.0 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
end end

Loading…
Cancel
Save