Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
aoz-003
Commits
a4510c71
Verified
Commit
a4510c71
authored
Jul 12, 2018
by
Kaspar Vollenweider
👻
Browse files
rename Period to Semester ... everywhere, views, methods, scopes...
parent
2e61480e
Changes
10
Hide whitespace changes
Inline
Side-by-side
app/controllers/billing_expenses_controller.rb
View file @
a4510c71
class
BillingExpensesController
<
ApplicationController
before_action
:set_billing_expense
,
only:
[
:show
,
:update_overwritten_amount
,
:destroy
]
before_action
:set_billing_
period
s
,
only:
[
:index
,
:new
,
:create
]
before_action
:set_billing_
semester
s
,
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_
period
s
@billing_
period
s
=
BillingExpense
.
generate_
period
s
def
set_billing_
semester
s
@billing_
semester
s
=
BillingExpense
.
generate_
semester_filter
s
end
def
set_selection
@selected_billing_expenses
=
params
[
:selected_billing_expenses
].
presence
||
[]
end
def
default_billing_
period
@billing_
period
s
.
first
[
:value
]
def
default_billing_
semester
@billing_
semester
s
.
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
)
...
...
app/models/billing_expense.rb
View file @
a4510c71
...
...
@@ -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_
period
s
period
s
=
[]
def
self
.
generate_
semester_filter
s
semester
s
=
[]
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
...
...
app/models/hour.rb
View file @
a4510c71
...
...
@@ -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
}
...
...
app/views/billing_expenses/index.html.slim
View file @
a4510c71
...
...
@@ -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_
period
s
)
=
custom_filter_dropdown
(
t_attr
(
:
semester
,
BillingExpense
),
*
@billing_
semester
s
)
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
)
app/views/billing_expenses/new.html.slim
View file @
a4510c71
...
...
@@ -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
config/locales/de.yml
View file @
a4510c71
...
...
@@ -296,7 +296,7 @@ de:
amount
:
Betrag
assignment
:
Begleitung
created_by
:
Erstellt von
period
:
Periode
semester
:
Semester
certificate
:
<<
:
*id-generic_keys
assignment
:
Einsatz
...
...
test/models/billing_expense_test.rb
View file @
a4510c71
...
...
@@ -68,11 +68,11 @@ class BillingExpenseTest < ActiveSupport::TestCase
refute_equal
creator
,
hour1c
.
reload
.
reviewer
end
test
'generate_
period
s without hours'
do
periods
=
BillingExpense
.
generate_
period
s
test
'generate_
semester_filter
s without hours'
do
periods
=
BillingExpense
.
generate_
semester_filter
s
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_
period
s with hours'
do
test
'generate_
semester_filter
s 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_
period
s
periods
=
BillingExpense
.
generate_
semester_filter
s
assert_equal
[
{
q: :period
,
value:
'2015-06-01'
,
text:
'Juni 2015 - November 2015'
},
...
...
test/models/hour_test.rb
View file @
a4510c71
...
...
@@ -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
...
...
test/models/volunteer_scopes_test.rb
View file @
a4510c71
...
...
@@ -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
]
...
...
test/system/billing_expenses_test.rb
View file @
a4510c71
...
...
@@ -48,13 +48,13 @@ class BillingExpensesTest < ApplicationSystemTestCase
refute_text
@volunteer3
refute_text
@volunteer4
click_link
'
Periode: Dezember 2017 - Mai
2018'
click_link
'
Juni 2017 - Novemb
er 2017'
click_link
'
Semester: 1. Semester
2018'
click_link
'
2. Semest
er 2017'
assert_text
"
#{
@volunteer4
}
#{
@volunteer4
.
iban
}
5.5 Stunden Fr. 50.00"
refute_text
@volunteer1
click_link
'
Periode: Juni 2017 - Novemb
er 2017'
click_link
'
Semester: 2. Semest
er 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 - Novemb
er 2017'
click_link
'
Semester: 1. Semester
2018'
click_link
'
2. Semest
er 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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment