Class: PayrollHolidaysController
Instance Method Summary
collapse
#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token
Instance Method Details
#create ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/controllers/payroll_holidays_controller.rb', line 29
def create
payroll_holiday = PayrollHoliday.new(**private_holiday_params)
raise ActiveRecord::RecordInvalid.new(payroll_holiday) unless payroll_holiday.valid?
payroll_holiday.create_or_update_procedure
render json: {
message: I18n.t('messages.payroll_holiday_created')
}
rescue ActiveRecord::RecordInvalid => e
render json: {
errors: e.record.errors,
message: e.record.errors.full_messages.join(', '),
redirect_to: '/app/payroll/holidays'
}, status: :bad_request
end
|
#index ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/controllers/payroll_holidays_controller.rb', line 7
def index
order_by = params[:order_by] || 'date'
order_direction = params[:order_direction] || 'asc'
query = params[:query] || ''
limit = params[:limit] || 10
offset = params[:offset] || 0
year = params[:year] || Date.today.year
data, metadata = fetch_records(
records: PayrollHoliday.for_year(year),
order_by: order_by,
fields: %w[date description active payroll_holiday_id],
search_fields: ['description'],
order: order_direction,
query: query,
limit: limit,
offset: offset
).values_at(:data, :metadata)
render json: { data: data, metadata: metadata }
end
|
#update_from_table_edits ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/controllers/payroll_holidays_controller.rb', line 46
def update_from_table_edits
request.params[:rows_edits].each do |row_edits|
row_hash = row_edits[:rowHash]
edits = row_edits[:edits]
payroll_holiday = PayrollHoliday.find(row_hash[:payroll_holiday_id])
attributes = edits.slice(:description, :active).reject { |_, v| v.nil? }
payroll_holiday.assign_attributes(attributes)
raise ActiveRecord::RecordInvalid.new(payroll_holiday) unless payroll_holiday.valid?
payroll_holiday.create_or_update_procedure
end
render json: {
message: I18n.t('messages.payroll_holidays_updated')
}
rescue ActiveRecord::RecordInvalid => e
render json: {
message: e.record.errors.full_messages.join(', ')
}, status: :bad_request
end
|
#years ⇒ Object
68
69
70
71
72
|
# File 'app/controllers/payroll_holidays_controller.rb', line 68
def years
render json: {
data: PayrollHoliday.years
}
end
|