Commit c43687c8 authored by Tugce Nur Tas's avatar Tugce Nur Tas

Merge branch 'changes/feedback-submitted-status-on-billing-expenses' into 'develop'

changes/show semester feedback status on billing expenses

See merge request !922
parents 89c32874 d8129470
Pipeline #37538 failed with stage
in 15 minutes and 29 seconds
......@@ -108,8 +108,6 @@ class BillingExpensesController < ApplicationController
if params[:q].blank?
set_default_filter(semester: default_billing_semester)
default_billing_semester
elsif params[:q][:all].present?
nil
elsif !@billing_semester_filters.pluck(:value).include? params[:q][:semester]
params.permit![:q][:semester] = default_billing_semester
default_billing_semester
......
module FilterDropdownHelper
def custom_filter_dropdown(name, *filters)
_custom_filter_dropdown_general(name, true, *filters)
end
def custom_filter_dropdown_no_all(name, *filters)
_custom_filter_dropdown_general(name, false, *filters)
end
def _custom_filter_dropdown_general(name, all_link, *filters)
filter_keys = filters.map { |filter| filter[:q] }
filter_keys += filters.map { |filter| filter[:qs] }
filters = custom_filter_dropdown_filters(filters, filter_keys)
render_filter_dropdown top_text: name + custom_text_end(filters),
all_url: filter_keys, filters: filters
all_url: filter_keys, filters: filters, all_link: all_link
end
def custom_filter_dropdown_filters(filters, filter_keys)
......@@ -19,7 +27,7 @@ module FilterDropdownHelper
filter.merge(url: url_for(q_args), link_class: list_filter_link_class(filter[:active]))
end
end
def custom_filter_q_arg(filter, multi_qs, value, *excludes)
q_values = search_parameters.merge(multi_qs.map { |q| [q, value.to_s] }.to_h) if multi_qs
(q_values || search_parameters).except(*excludes).merge("#{filter}": value.to_s)
......@@ -36,7 +44,7 @@ module FilterDropdownHelper
)
end
render_filter_dropdown top_text: toggler_text(attribute.to_sym, [attribute_q]),
all_url: attribute_q, filters: filters
all_url: attribute_q, filters: filters, all_link: true
end
def boolean_filter_dropdown(attribute, collection = nil)
......@@ -50,7 +58,7 @@ module FilterDropdownHelper
)
end
render_filter_dropdown top_text: toggler_text(attribute, filters.pluck(:q)),
all_url: filters.pluck(:q), filters: filters
all_url: filters.pluck(:q), filters: filters, all_link: true
end
# Creates a filter dropdown that filters a boolean attribute to either true or false
......@@ -72,8 +80,8 @@ module FilterDropdownHelper
end
def render_filter_dropdown(locals)
render template: 'application/filter_dropdown',
locals: locals.merge(all_url: all_url_for(locals[:all_url]))
locals.merge!(all_url: all_url_for(locals[:all_url])) if locals[:all_link]
render template: 'application/filter_dropdown', locals: locals
end
def custom_text_end(filters)
......
......@@ -37,10 +37,10 @@ class SemesterProcessVolunteer < ApplicationRecord
scope :active_missions, lambda {
joins(:semester_process_volunteer_missions).includes(semester_process_volunteer_missions: [:assignment, :group_assignment])
.where("(semester_process_volunteer_missions.assignment_id IS NOT NULL AND
.where("(semester_process_volunteer_missions.assignment_id IS NOT NULL AND
assignments.period_end IS NULL)
OR
(semester_process_volunteer_missions.group_assignment_id IS NOT NULL AND
OR
(semester_process_volunteer_missions.group_assignment_id IS NOT NULL AND
group_assignments.period_end is NULL)")
.references(:assignments, :group_assignments)
}
......@@ -53,6 +53,14 @@ class SemesterProcessVolunteer < ApplicationRecord
left_outer_joins(:semester_feedbacks).where(semester_feedbacks: { id: nil})
}
scope :unsubmitted, -> { where(commited_at: nil) }
scope :submitted, -> { where.not(commited_at: nil) }
scope :in_semester, lambda { |semester|
semester = (Date.parse(semester)..Date.parse(semester).advance(months: 5).end_of_month) if semester.is_a?(String)
joins(:semester_process).where('semester_processes.semester && daterange(?,?)', semester.begin, semester.end)
}
attr_accessor :hours
def hours
......
......@@ -180,14 +180,25 @@ class Volunteer < ApplicationRecord
def self.feedback_overdue(semester)
joins(:contact).where(id: have_semester_process(semester).where("semester_process_volunteers.commited_at IS NULL").ids)
end
def unsubmitted_semester_feedbacks
semester_process_volunteers.where(commited_at: nil)
semester_process_volunteers.unsubmitted
end
def submitted_semester_feedbacks
semester_process_volunteers.submitted
end
def unsubmitted_semester_feedbacks?
return false if unsubmitted_semester_feedbacks.blank?
true
semester_process_volunteers.unsubmitted.any?
end
def submitted_semester_feedbacks_covers_semester?(selected_billing_semester)
submitted_semester_feedbacks.in_semester(selected_billing_semester).any?
end
def unsubmitted_semester_feedbacks_covers_semester?(selected_billing_semester)
unsubmitted_semester_feedbacks.in_semester(selected_billing_semester).any?
end
## Activness Scopes
......@@ -372,7 +383,7 @@ class Volunteer < ApplicationRecord
def assignment_logs_started?
assignment_logs.started.any?
end
end
def group_assignment_started?
group_assignments.started.any?
......
- all_link ||= false
li.dropdown
a*{ class: 'dropdown-toggle btn btn-default btn-sm', role: 'button', href: '#',
data: { toggle: 'dropdown' }, aria: { expanded: 'false', haspopup: 'true' } }
=> top_text
span.caret
ul.dropdown-menu
li= link_to t('all'), all_url
li.divider[role="separator"]
- if all_link
li= link_to t('all'), all_url
li.divider[role="separator"]
- filters.each do |filter|
li= link_to filter[:text], filter[:url], class: filter[:link_class]
......@@ -7,7 +7,7 @@ h1 Spesenformulare erfassen
ul.list-inline
= button_link icon_span(:back), billing_expenses_path
li= clear_filter_button
= custom_filter_dropdown(t_attr(:semester, BillingExpense), *@billing_semester_filters)
= custom_filter_dropdown_no_all(t_attr(:semester, BillingExpense), *@billing_semester_filters)
li= f.button :submit, 'Selektierte Spesenformulare erstellen', 'data-confirm' => 'Sind Sie sicher dass Sie die Spesenformulare für die ausgewählten Freiwilligen erstellen möchten?'
.table-responsive
......@@ -28,8 +28,10 @@ h1 Spesenformulare erfassen
td= check_box_tag 'selected_volunteers[]', volunteer.id,
@selected_volunteers.include?(volunteer.id.to_s), disabled: !volunteer.iban?
td
- if volunteer.unsubmitted_semester_feedbacks?
span.label.label-danger Unbestätigt
- if volunteer.submitted_semester_feedbacks_covers_semester?(@selected_billing_semester)
span.label.label-success Bestätigt
- elsif volunteer.unsubmitted_semester_feedbacks_covers_semester?(@selected_billing_semester)
span.label.label-warning Unbestätigt
td= link_to volunteer, edit_volunteer_path(volunteer)
td
- if volunteer.iban?
......
......@@ -121,16 +121,6 @@ class BillingExpensesTest < ApplicationSystemTestCase
assert_text "#{volunteer1} #{volunteer1.iban} 26 Stunden Fr. 100.00 2. Semester 2017"
assert_text "#{volunteer2} #{volunteer2.iban} 15 Stunden Fr. 50.00 2. Semester 2017"
refute_text volunteer3
visit billing_expenses_path
click_link 'Semester: 1. Semester 2018'
click_link 'Alle'
click_link 'Spesenformulare erfassen'
assert_text "#{volunteer1} #{volunteer1.iban} 26 Stunden Fr. 100.00 2. Semester 2017"
assert_text "#{volunteer2} #{volunteer2.iban} 41 Stunden Fr. 100.00" \
' 2. Semester 2017 – 1. Semester 2018'
assert_text "#{volunteer3} #{volunteer3.iban} 3 Stunden Fr. 50.00 1. Semester 2018"
end
test 'creating_a_billing_expense_should_respect_semester_filter' do
......@@ -153,10 +143,10 @@ class BillingExpensesTest < ApplicationSystemTestCase
end
assert_text "#{volunteer} #{volunteer.iban} 16 Stunden Fr. 50.00 1. Semester 2018"
# creating billing_expense for the all remaining hours
# creating billing_expense for hours in 2. Semester 2017
visit billing_expenses_path
click_link 'Semester: 1. Semester 2018'
click_link 'Alle'
click_link '2. Semester 2017'
click_link 'Spesenformulare erfassen'
within "##{dom_id(volunteer)}" do
......@@ -171,30 +161,6 @@ class BillingExpensesTest < ApplicationSystemTestCase
click_link 'Semester: 1. Semester 2018'
click_link 'Alle'
assert_text "#{volunteer} #{volunteer.iban} 26 Stunden Fr. 100.00 2. Semester 2017"
# creating billing_expense for all hours in multiple semesters
volunteer = create :volunteer
create :hour, volunteer: volunteer, hours: 26, meeting_date: time_z(2017, 11, 1)
create :hour, volunteer: volunteer, hours: 16, meeting_date: time_z(2018, 2, 1)
visit billing_expenses_path
click_link 'Semester: 1. Semester 2018'
click_link 'Alle'
click_link 'Spesenformulare erfassen'
within "##{dom_id(volunteer)}" do
check 'selected_volunteers[]'
end
assert_checked_field 'selected_volunteers[]', count: 1
page.accept_confirm do
click_button 'Selektierte Spesenformulare erstellen'
end
click_link 'Semester: 1. Semester 2018'
click_link 'Alle'
assert_text "#{volunteer} #{volunteer.iban} 42 Stunden Fr. 100.00"\
' 2. Semester 2017 – 1. Semester 2018'
end
test 'volunteer profile shows only billing expenses for this volunteer' do
......
Markdown is supported
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