Verified Commit 5fa6dbbf authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

semester filters only for semesters with hours

parent 873d75cc
......@@ -73,22 +73,24 @@ class BillingExpense < ApplicationRecord
end
def self.generate_semester_filters(scope = :billed)
semesters = []
first_semester = semester_from_hours(scope, date_position: :minimum)
last_semester = semester_from_hours(scope)
until last_semester < first_semester
semesters << {
q: :semester,
value: last_semester.strftime('%Y-%m-%d'),
text: "#{semester_of_year(last_semester)}. Semester #{semester_display_year(last_semester)}"
}
scoped_hours = Hour.public_send(scope)
first_semester = semester_from_hours(scoped_hours, date_position: :minimum)
last_semester = semester_from_hours(scoped_hours)
semesters = [semester_filter_hash(last_semester)]
semester_back_count(first_semester, last_semester).times do
last_semester = last_semester.advance(months: -SEMESTER_LENGTH)
next if scoped_hours.semester(last_semester).blank?
semesters << semester_filter_hash(last_semester)
end
semesters
end
def self.semester_filter_hash(date)
{ q: :semester, value: date.strftime('%Y-%m-%d'),
text: "#{semester_of_year(date)}. Semester #{semester_display_year(date)}" }
end
def final_amount
overwritten_amount.presence || amount
end
......
......@@ -18,8 +18,11 @@ module BillingExpenseSemesterUtils
end
end
def self.semester_from_hours(scope, date_position: :maximum)
hours = Hour.public_send(scope)
def self.semester_back_count(first_date, last_date)
((last_date.to_f - first_date.to_f) / BillingExpense::SEMESTER_LENGTH.months.to_f).ceil.to_i
end
def self.semester_from_hours(hours, date_position: :maximum)
if hours.blank?
current_semester_start
elsif hours.count > 1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment