Browse Source

add fortschritt

main
Christoph Marzell 3 weeks ago
parent
commit
e5c78ecc86
  1. 24
      app/controllers/entries_controller.rb
  2. 5
      app/views/entries/index.html.erb

24
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)

5
app/views/entries/index.html.erb

@ -77,6 +77,7 @@
<th>Soll (h)</th>
<th>Wöchentlich</th>
<th>Vorauss. Ende</th>
<th>Fortschritt</th>
</tr>
</thead>
<tbody>
@ -95,6 +96,10 @@
<td><%= soll || "—" %> h</td>
<td><%= weekly || "—" %> h/Woche</td>
<td><%= ende.present? ? ende.strftime("%d.%m.%Y") : "—" %></td>
<td>
<% percent = @completion_percent_by_typ_art[[typ, art]] %>
<%= percent ? "#{percent} %" : "—" %>
</td>
</tr>
<% end %>
<% end %>

Loading…
Cancel
Save