|
7 | 7 |
|
8 | 8 | module Evaluations |
9 | 9 | class AbsencesEval < Evaluations::Evaluation |
| 10 | + include EvaluatorHelper |
| 11 | + include FormatHelper |
| 12 | + |
10 | 13 | self.sub_evaluation = 'employeeabsences' |
11 | 14 | self.division_column = :employee_id |
12 | 15 | self.label = 'Members Absenzen' |
13 | 16 | self.absences = true |
14 | 17 | self.detail_columns = detail_columns.reject { |i| i == :billable } |
15 | 18 | self.detail_labels = detail_labels.merge(account: 'Absenz') |
16 | 19 |
|
17 | | - attr_reader :department_id |
| 20 | + attr_reader :department_id, :sort_conditions |
18 | 21 |
|
19 | | - def initialize(department_id = nil, **worktime_search_conditions) |
| 22 | + def initialize(department_id = nil, sort_conditions = nil, **worktime_search_conditions) |
20 | 23 | super(Employee, **worktime_search_conditions) |
21 | 24 | @department_id = department_id |
| 25 | + @sort_conditions = sort_conditions |
| 26 | + end |
| 27 | + |
| 28 | + def divisions(period = nil, times = nil) |
| 29 | + employees_with_absences(period, times).map do |e| |
| 30 | + unformatted_vacations = remaining_vacations(e, format: false) |
| 31 | + e.remaining_vacations = format_days(unformatted_vacations) |
| 32 | + e.sort_col = unformatted_vacations * descending |
| 33 | + e |
| 34 | + end.sort_by(&:sort_col) |
22 | 35 | end |
23 | 36 |
|
24 | | - def divisions(period = nil) |
| 37 | + def employees_with_absences(period, times) |
25 | 38 | scope = Employee.employed_ones(period || Period.current_year) |
26 | 39 |
|
27 | | - return scope if department_id.blank? |
| 40 | + scope = scope.where(department_id: department_id) if department_id.present? |
| 41 | + scope.filter do |e| |
| 42 | + times_or_plannings?(self, e, times, [period]) |
| 43 | + end |
| 44 | + end |
28 | 45 |
|
29 | | - scope.where(department_id:) |
| 46 | + def division_header |
| 47 | + 'Member' |
30 | 48 | end |
31 | 49 |
|
32 | 50 | def employee_id |
33 | 51 | division&.id |
34 | 52 | end |
35 | 53 |
|
36 | 54 | def division_supplement(_user) |
37 | | - [[:remaining_vacations, 'Übrige Ferien', 'right'], |
38 | | - [:overtime_vacations_tooltip, '', 'left']] |
| 55 | + { |
| 56 | + remaining_vacations: { title: 'Übrige Ferien', align: 'right', sortable: true }, |
| 57 | + overtime_vacations_tooltip: {} |
| 58 | + } |
| 59 | + end |
| 60 | + |
| 61 | + private |
| 62 | + |
| 63 | + def descending |
| 64 | + sort_conditions && sort_conditions['sort_dir'] == 'desc' ? -1 : 1 |
39 | 65 | end |
40 | 66 | end |
41 | 67 | end |
0 commit comments