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

rename Period to Semester ... everywhere, views, methods, scopes...

parent 2e61480e
class BillingExpensesController < ApplicationController
before_action :set_billing_expense, only: [:show, :update_overwritten_amount, :destroy]
before_action :set_billing_periods, only: [:index, :new, :create]
before_action :set_billing_semesters, only: [:index, :new, :create]
before_action :set_selection, only: [:index, :download]
def index
authorize BillingExpense
set_default_filter(period: default_billing_period)
set_default_filter(semester: default_billing_semester)
@q = policy_scope(BillingExpense).ransack(params[:q])
@q.sorts = ['created_at desc'] if @q.sorts.empty?
@billing_expenses = @q.result
......@@ -54,8 +54,8 @@ class BillingExpensesController < ApplicationController
@billing_expense = BillingExpense.new
authorize @billing_expense
@selected_billing_period = selected_billing_period
@q = Volunteer.with_billable_hours(@selected_billing_period).ransack(params[:q])
@selected_billing_semester = selected_billing_semester
@q = Volunteer.with_billable_hours(@selected_billing_semester).ransack(params[:q])
@volunteers = @q.result
@selected_volunteers = params[:selected_volunteers].presence || []
end
......@@ -64,9 +64,9 @@ class BillingExpensesController < ApplicationController
authorize BillingExpense, :create?
selected_volunteers = params[:selected_volunteers]
selected_period = params[:selected_period]
selected_semester = params[:selected_semester]
volunteers = Volunteer.need_refunds.where(id: selected_volunteers)
BillingExpense.create_for!(volunteers, current_user, selected_period)
BillingExpense.create_for!(volunteers, current_user, selected_semester)
redirect_to billing_expenses_url,
notice: 'Spesenformulare wurden erfolgreich erstellt.'
......@@ -92,24 +92,26 @@ class BillingExpensesController < ApplicationController
authorize @billing_expense
end
def set_billing_periods
@billing_periods = BillingExpense.generate_periods
def set_billing_semesters
@billing_semesters = BillingExpense.generate_semester_filters
end
def set_selection
@selected_billing_expenses = params[:selected_billing_expenses].presence || []
end
def default_billing_period
@billing_periods.first[:value]
def default_billing_semester
@billing_semesters.first[:value]
end
def selected_billing_period
filter = params[:q]
return default_billing_period unless filter.present?
return nil if filter[:all].present?
return filter[:period]
def selected_billing_semester
if params[:q].blank?
default_billing_semester
elsif params[:q][:all].present?
nil
else
params[:q][:semester]
end
end
def pdf_file_name(record)
......
......@@ -2,7 +2,7 @@ class BillingExpense < ApplicationRecord
include ImportRelation
include FullBankDetails
PERIOD = 6.months
SEMESTER_LENGTH = 6.months
attr_accessor :import_mode
......@@ -14,7 +14,7 @@ class BillingExpense < ApplicationRecord
default_scope { order(created_at: :desc) }
scope :period, ->(date) { joins(:hours).merge(Hour.period(date)) }
scope :semester, ->(date) { joins(:hours).merge(Hour.period(date)) }
FINAL_AMOUNT_SQL = "CASE WHEN overwritten_amount IS NULL THEN amount ELSE overwritten_amount END".freeze
scope :sort_by_final_amount_asc, lambda {
......@@ -30,7 +30,7 @@ class BillingExpense < ApplicationRecord
validates :amount, inclusion: { in: AMOUNT }, unless: :import_mode
def self.ransackable_scopes(auth_object = nil)
['period']
['semester']
end
def ransortable_attributes(auth_object = nil)
......@@ -71,8 +71,8 @@ class BillingExpense < ApplicationRecord
end
end
def self.generate_periods
periods = []
def self.generate_semester_filters
semesters = []
hours = Hour.billed
oldest_date = hours.minimum(:meeting_date) || Time.zone.now
......@@ -80,22 +80,29 @@ class BillingExpense < ApplicationRecord
start_of_year = newest_date.beginning_of_year - 1.month
date = start_of_year
date += PERIOD if newest_date >= start_of_year + PERIOD
date += SEMESTER_LENGTH if newest_date >= start_of_year + SEMESTER_LENGTH
until date < oldest_date - PERIOD
periods << {
q: :period,
until date < oldest_date - SEMESTER_LENGTH
display_year = date.year
display_year += 1 if date.month == 12
semesters << {
q: :semester,
value: date.strftime('%Y-%m-%d'),
text: '%s - %s' % [
I18n.l(date, format: '%B %Y'),
I18n.l(date + PERIOD - 1.day, format: '%B %Y')
]
text: "#{semester_of_year(date)}. Semester #{display_year}"
}
date -= PERIOD
date -= SEMESTER_LENGTH
end
periods
semesters
end
def self.semester_of_year(date)
if (6..11).cover? date.month
2
else
1
end
end
def final_amount
......
......@@ -23,7 +23,7 @@ class Hour < ApplicationRecord
date = Time.zone.parse(date) unless date.is_a? Time
return if date.blank?
date_between(:meeting_date, date, date + BillingExpense::PERIOD)
date_between(:meeting_date, date, date + BillingExpense::SEMESTER_LENGTH)
end
}
......
......@@ -10,7 +10,7 @@ h1
html: { class: 'form-ignore-changes', target: '_blank' } do |f|
ul.list-inline
li= clear_filter_button
= custom_filter_dropdown(t_attr(:period, BillingExpense), *@billing_periods)
= custom_filter_dropdown(t_attr(:semester, BillingExpense), *@billing_semesters)
li=> f.button :submit, 'Auswahl herunterladen', data: { disable_with: false }
li
- if @volunteer
......@@ -29,7 +29,7 @@ h1
th= t_attr(:bank_details, Volunteer)
th= t_attr(:hours)
th= sort_link @q, :final_amount
th Periode
th Semester
- if policy(BillingExpense).superadmin_privileges?
th= sort_link @q, :user_profile_contact_last_name, t_attr(:created_by)
th= sort_link @q, :created_at
......@@ -51,7 +51,7 @@ h1
td= record.full_bank_details
td= link_to format_hours(record.hours.total_hours), volunteer_hours_path(record.volunteer)
td= format_currency record.final_amount
td= format_hours_period record.hours
td= format_hours_semester record.hours
- if policy(BillingExpense).superadmin_privileges?
td= link_to record.user, profile_url_path(record.user)
td= l(record.created_at.to_date)
......@@ -3,7 +3,7 @@
h1 Spesenformulare erfassen
= simple_form_for @billing_expense do |f|
= hidden_field_tag 'selected_period', @selected_billing_period
= hidden_field_tag 'selected_semester', @selected_billing_semester
.row
.col-xs-12
=> button_link navigation_glyph(:back), billing_expenses_path
......@@ -33,4 +33,4 @@ h1 Spesenformulare erfassen
span.label.label-danger Keine IBAN angegeben
td= link_to format_hours(volunteer.total_hours), volunteer_hours_path(volunteer)
td= format_currency BillingExpense.amount_for(volunteer.total_hours)
td= format_hours_period volunteer.hours.period(@selected_billing_period).billable
td= format_hours_semester volunteer.hours.period(@selected_billing_semester).billable
......@@ -296,7 +296,7 @@ de:
amount: Betrag
assignment: Begleitung
created_by: Erstellt von
period: Periode
semester: Semester
certificate:
<<: *id-generic_keys
assignment: Einsatz
......
......@@ -68,11 +68,11 @@ class BillingExpenseTest < ActiveSupport::TestCase
refute_equal creator, hour1c.reload.reviewer
end
test 'generate_periods without hours' do
periods = BillingExpense.generate_periods
test 'generate_semester_filters without hours' do
periods = BillingExpense.generate_semester_filters
now = Time.zone.now
if now > now.beginning_of_year - 1.month + BillingExpense::PERIOD
if now > now.beginning_of_year - 1.month + BillingExpense::SEMESTER_LENGTH
value = "#{now.year}-06-01"
text = "Juni #{now.year} - November #{now.year}"
else
......@@ -83,13 +83,13 @@ class BillingExpenseTest < ActiveSupport::TestCase
assert_equal [{ q: :period, value: value, text: text }], periods
end
test 'generate_periods with hours' do
test 'generate_semester_filters with hours' do
hour1 = create :hour, meeting_date: '2014-02-03'
hour2 = create :hour, meeting_date: '2015-06-30'
create :hour, meeting_date: '2017-06-30'
create :billing_expense, hours: [hour1, hour2]
periods = BillingExpense.generate_periods
periods = BillingExpense.generate_semester_filters
assert_equal [
{ q: :period, value: '2015-06-01', text: 'Juni 2015 - November 2015' },
......
......@@ -11,9 +11,9 @@ class HourTest < ActiveSupport::TestCase
end
test 'period returns hours for a billing_expense period' do
current_period = BillingExpense::PERIOD
current_period = BillingExpense::SEMESTER_LENGTH
a_period_ago = current_period.ago
last_period_ago = a_period_ago - BillingExpense::PERIOD
last_period_ago = a_period_ago - BillingExpense::SEMESTER_LENGTH
format = '%Y-%m-%d'
volunteer = create :volunteer
......
......@@ -331,8 +331,8 @@ class VolunteerScopesTest < ActiveSupport::TestCase
end
test 'with_billable_hours returns volunteers with billable hours for an optional period' do
current_period_ago = BillingExpense::PERIOD.ago
last_period_ago = current_period_ago - BillingExpense::PERIOD
current_period_ago = BillingExpense::SEMESTER_LENGTH.ago
last_period_ago = current_period_ago - BillingExpense::SEMESTER_LENGTH
format = '%Y-%m-%d'
volunteers_in_current_period_assertion = [@group_offer_member, @has_assignments]
volunteers_in_last_period_assertion = [@has_multiple, @has_active_and_inactive]
......
......@@ -48,13 +48,13 @@ class BillingExpensesTest < ApplicationSystemTestCase
refute_text @volunteer3
refute_text @volunteer4
click_link 'Periode: Dezember 2017 - Mai 2018'
click_link 'Juni 2017 - November 2017'
click_link 'Semester: 1. Semester 2018'
click_link '2. Semester 2017'
assert_text "#{@volunteer4} #{@volunteer4.iban} 5.5 Stunden Fr. 50.00"
refute_text @volunteer1
click_link 'Periode: Juni 2017 - November 2017'
click_link 'Semester: 2. Semester 2017'
click_link 'Alle'
assert_link 'Herunterladen', count: 2
......@@ -116,8 +116,8 @@ class BillingExpensesTest < ApplicationSystemTestCase
visit billing_expenses_path
click_link 'Periode: Dezember 2017 - Mai 2018'
click_link 'Juni 2017 - November 2017'
click_link 'Semester: 1. Semester 2018'
click_link '2. Semester 2017'
click_link 'Spesenformulare erstellen'
assert_text "#{volunteer1} #{volunteer1.iban} 26 Stunden Fr. 100.00 #{period_text(hour2, hour1)}"
assert_text "#{volunteer2} #{volunteer2.iban} 15 Stunden Fr. 50.00 #{period_text(hour4, hour4)}"
......@@ -125,7 +125,7 @@ class BillingExpensesTest < ApplicationSystemTestCase
visit billing_expenses_path
click_link 'Periode: Dezember 2017 - Mai 2018'
click_link 'Semester: 1. Semester 2018'
click_link 'Alle'
click_link 'Spesenformulare erstellen'
assert_text "#{volunteer1} #{volunteer1.iban} 26 Stunden Fr. 100.00 #{period_text(hour2, hour1)}"
......@@ -156,7 +156,7 @@ class BillingExpensesTest < ApplicationSystemTestCase
# creating billing_expense for the all remaining hours
visit billing_expenses_path
click_link 'Periode: Dezember 2017 - Mai 2018'
click_link 'Semester: 1. Semester 2018'
click_link 'Alle'
click_link 'Spesenformulare erstellen'
......@@ -169,7 +169,7 @@ class BillingExpensesTest < ApplicationSystemTestCase
click_button 'Spesenformulare erstellen'
end
click_link 'Periode: Dezember 2017 - Mai 2018'
click_link 'Semester: 1. Semester 2018'
click_link 'Alle'
assert_text "#{volunteer} #{volunteer.iban} 26 Stunden Fr. 100.00 #{period_text(hour1, hour1)}"
......@@ -179,7 +179,7 @@ class BillingExpensesTest < ApplicationSystemTestCase
hour2 = create :hour, volunteer: volunteer, hours: 16, meeting_date: @date + 1.month
visit billing_expenses_path
click_link 'Periode: Dezember 2017 - Mai 2018'
click_link 'Semester: 1. Semester 2018'
click_link 'Alle'
click_link 'Spesenformulare erstellen'
......@@ -192,7 +192,7 @@ class BillingExpensesTest < ApplicationSystemTestCase
click_button 'Spesenformulare erstellen'
end
click_link 'Periode: Dezember 2017 - Mai 2018'
click_link 'Semester: 1. Semester 2018'
click_link 'Alle'
assert_text "#{volunteer} #{volunteer.iban} 42 Stunden Fr. 100.00 #{period_text(hour1, hour2)}"
end
......@@ -257,7 +257,7 @@ class BillingExpensesTest < ApplicationSystemTestCase
use_rack_driver
visit billing_expenses_path
click_link 'Periode: Dezember 2017 - Mai 2018'
click_link 'Semester: 1. Semester 2018'
click_link 'Alle'
page.all('input[type="checkbox"]').each(&:click)
......
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