Browse Source

add infos

main
Christoph Marzell 1 month ago
parent
commit
e401ac2074
  1. 3
      app/controllers/entries_controller.rb
  2. 20
      app/models/entry.rb
  3. 92
      app/views/entries/index.html.erb

3
app/controllers/entries_controller.rb

@ -37,8 +37,9 @@ class EntriesController < ApplicationController
end
@fortbildungskosten_by_year = Entry.total_fortbildungskosten_by_year(current_user)
@selbstsupervision_by_year = Entry.total_selbsterfahrungskosten_by_year(current_user)
@selbsterfahrungskosten_by_year = Entry.total_selbsterfahrungskosten_by_year(current_user)
@allekosten_by_year = Entry.total_semesterkosten_by_year(current_user)
# Voraussichtliches Ende je Kombination basierend auf weekly_target_matrix
@estimated_end_by_typ_art = {}
@remaining_minutes_matrix.each do |typ, arts|

20
app/models/entry.rb

@ -12,12 +12,18 @@ class Entry < ApplicationRecord
before_save :normalize_time
PRAKTIKUMSTYPEN = %w[propädeutikum fachspezifikum]
ENTRY_ARTEN = %w[Praktikum Selbsterfahrung Supervision Fortbildung]
ENTRY_ARTEN = %w[Praktikum Selbsterfahrung Supervision Fortbildung Semesterkosten]
validates :praktikums_typ, inclusion: { in: PRAKTIKUMSTYPEN }
validates :entry_art, inclusion: { in: ENTRY_ARTEN }
validates :distance_km, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
after_initialize :set_default_date, if: :new_record?
def set_default_date
self.date ||= Date.today
end
def kilometer_pauschale
return 0 unless distance_km.present?
distance_km * 0.42
@ -35,6 +41,18 @@ class Entry < ApplicationRecord
.transform_values { |entries| entries.sum { |e| e.kosten.to_f } }
end
def self.total_supervision_by_year(user)
where(user: user, entry_art: 'Supervision')
.group_by { |e| e.date.year }
.transform_values { |entries| entries.sum { |e| e.kosten.to_f } }
end
def self.total_semesterkosten_by_year(user)
where(user: user)
.group_by { |e| e.date.year }
.transform_values { |entries| entries.sum { |e| e.kosten.to_f } }
end
def jahr
date.year
end

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

@ -1,32 +1,65 @@
<div class="container my-4">
<h1 class="mb-4">Meine Einträge</h1>
<!-- 🔢 Zusammenfassung -->
<div class="mb-4">
<h5 class="mb-3">🚗 Fahrtkosten (Kilometergeld)</h5>
<% @total_kilometer_costs_by_year.each do |year, sum| %>
<p><strong><%= year %>:</strong>
<%= number_to_currency(sum, unit: "€", separator: ",", delimiter: ".", precision: 2) %>
</p>
<% end %>
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4">
<div class="col rounded border shadow-sm p-3">
<h5>🚗 Fahrtkosten (Kilometergeld)</h5>
<% @total_kilometer_costs_by_year.each do |year, sum| %>
<p><strong><%= year %>:</strong>
<%= number_to_currency(sum, unit: "€", separator: ",", delimiter: ".", precision: 2) %>
</p>
<% end %>
</div>
<div class="col rounded border shadow-sm p-3">
<h5>💶 Fortbildungskosten</h5>
<% @fortbildungskosten_by_year.each do |year, sum| %>
<p><strong><%= year %>:</strong>
<%= number_to_currency(sum, unit: "€", separator: ",", delimiter: ".", precision: 2) %>
</p>
<% end %>
</div>
<div class="col rounded border shadow-sm p-3">
<h5>🧠 Selbsterfahrungskosten</h5>
<% @selbsterfahrungskosten_by_year.each do |year, sum| %>
<p><strong><%= year %>:</strong>
<%= number_to_currency(sum, unit: "€", separator: ",", delimiter: ".", precision: 2) %>
</p>
<% end %>
</div>
<h5>💶 Fortbildungskosten</h5>
<% @fortbildungskosten_by_year.each do |year, sum| %>
<p><strong><%= year %>:</strong> <%= number_to_currency(sum, unit: "€", separator: ",", delimiter: ".", precision: 2) %></p>
<% end %>
<div class="col rounded border shadow-sm p-3">
<h5>👨‍🏫 Supervision</h5>
<% @selbstsupervision_by_year.each do |year, sum| %>
<p><strong><%= year %>:</strong>
<%= number_to_currency(sum, unit: "€", separator: ",", delimiter: ".", precision: 2) %>
</p>
<% end %>
</div>
<h5>💭 Selbsterfahrungskosten</h5>
<% @selbsterfahrungskosten_by_year.each do |year, sum| %>
<p><strong><%= year %>:</strong> <%= number_to_currency(sum, unit: "€", separator: ",", delimiter: ".", precision: 2) %></p>
<% end %>
<div class="col rounded border shadow-sm p-3">
<h5>📊 Gesamtkosten</h5>
<% @allekosten_by_year.each do |year, sum| %>
<p><strong><%= year %>:</strong>
<%= number_to_currency(sum, unit: "€", separator: ",", delimiter: ".", precision: 2) %>
</p>
<% end %>
</div>
<div class="col rounded border shadow-sm p-3">
<h5>🕒 Gesamtzeit</h5>
<p><strong><%= @total_minutes / 60 %> h <%= @total_minutes % 60 %> min</strong></p>
</div>
<p><strong>Gesamtzeit:</strong> <%= @total_minutes / 60 %> h <%= @total_minutes % 60 %> min</p>
</div>
</div>
<!-- 📊 Übersicht je Kombination -->
<div class="mb-4">
<h4>📊 Übersicht je Kombination</h4>
@ -75,7 +108,7 @@
</div>
<!-- 📋 Tabelle aller Einträge -->
<div class="mb-5">
<div class="m-1">
<h4 class="mb-3">📋 Einträge</h4>
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered" id="entriesTable">
@ -86,7 +119,7 @@
<th data-sort-index="2" class="sortable">Typ</th>
<th data-sort-index="3" class="sortable">Art</th>
<th data-sort-index="4" class="sortable">Kilometer</th>
<th data-sort-index="5" class="sortable">Pauschale</th>
<th data-sort-index="5" class="sortable"><div class="d-flex justify-content-between"><div>Pauschale</div><div>Kosten</div></div></th>
<th>Aktionen</th>
</tr>
</thead>
@ -96,16 +129,29 @@
<td><%= entry.date.strftime('%d.%m.%Y') %></td>
<td><%= entry.hours.to_i %>h <%= entry.minutes.to_i %>min</td>
<td>
<%= entry.entry_art == "Fortbildung" ? "Fortbildung" : entry.praktikums_typ.capitalize %>
<%= ["Fortbildung", "Semesterkosten"].include?(entry.entry_art) ? entry.entry_art : entry.praktikums_typ.capitalize %>
</td>
<td>
<%= entry.entry_art == "Fortbildung" ? entry.beschreibung : entry.entry_art.capitalize %>
<%= ["Fortbildung", "Semesterkosten"].include?(entry.entry_art) ? entry.beschreibung : entry.entry_art.capitalize %>
</td>
<td><%= entry.distance_km.to_f %> km</td>
<td><%= number_to_currency(entry.kilometer_pauschale, unit: "€", separator: ",", delimiter: ".") %></td>
<td>
<div class="d-flex justify-content-between">
<% if entry.kilometer_pauschale.present? %>
<div><%= number_to_currency(entry.kilometer_pauschale, unit: "€", separator: ",", delimiter: ".") %></div>
<% end %>
<% if entry.kosten.present? %>
<div><%= number_to_currency(entry.kosten, unit: "€", separator: ",", delimiter: ".") %></div>
<% end %>
</div>
</td>
<td class="text-end">
<div class="d-flex justify-content-between">
<%= link_to 'Bearbeiten', edit_entry_path(entry), class: 'btn btn-sm btn-outline-primary' %>
<%= link_to 'Löschen', entry_path(entry), class: 'btn btn-sm btn-outline-danger open-delete-modal' %>
</div>
</td>
</tr>
<% end %>

Loading…
Cancel
Save