3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/controllers/crm/reports/attendance_controller.rb', line 3
def attendance
@type = params[:type] || params[:commit]
@filter_params = OpenStruct.new(params[:f]) || {}
event_type = @filter_params[:event_type]
@start_date = parse_date_or_default(@filter_params[:date_gteq],Date.current.beginning_of_year)
@end_date = parse_date_or_default(@filter_params[:date_lteq], Date.current)
@results = nil
case @type
when 'attendance','schedule_vs_real'
@results = []
Employee.active_employees.order(:full_name).each do |employee|
status_filter = (event_type == 'not_working_timeoff' ? [3,4] : EmployeeEvent.statuses[event_type])
res = []
total_accumulated_time = 0.0
res << employee.first_name
res << ("#{employee.first_name[0,1]}" + "#{employee.last_name[0,3]}").upcase
@start_date.upto(@end_date).each do |date|
accumulated_time = 0
employee.employee_events.where(date: date, status: status_filter).each do |event|
accumulated_time = ((event.event_time || 0) - (event.broken_down_time || 0))
end
res << ((accumulated_time/3600).positive? ? accumulated_time/3600.to_f : '')
total_accumulated_time += accumulated_time
end
res << ((total_accumulated_time/3600).positive? ? total_accumulated_time/3600.round(2) : '')
@results << res
end
when 'attendance_office_and_remote'
@results = EmployeeWorkSchedule.joins(:employee).where("inactive = false").all
when 'banked_days'
@results = EmployeeEvent.from_active_employees.where("date >= ? and date <= ? and status = ?", @start_date, @end_date, EmployeeEvent.statuses[:banked_days] )
when 'attendance_per_department'
@results = EmployeeEvent.from_active_employees.where("date >= ? and date <= ?", @start_date, @end_date)
when 'uneschedule'
@results = EmployeeEvent.from_active_employees.where("date - created_at::Date < ?", 4)
when 'productivity'
@results = Employee.active_employees.select("parties.id AS employee", "employee_events.*").joins("LEFT JOIN employee_events ON employee_events.employee_id = parties.id").where("employee_events.date BETWEEN ? AND ? OR employee_events.id IS NULL", @start_date, @end_date)
@days = (@end_date - @start_date).to_i
else
@results = []
end
end
|