Class: PayrollCalculationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/payroll_calculations_controller.rb

Instance Method Summary collapse

Methods included from AuthentificationHelper

#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

#indexObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/payroll_calculations_controller.rb', line 14

def index
  data,  = EmployeePayrollCalculation.where_procedure(
    employee_id: params[:employee_id],
    limit: params[:limit]&.to_i || 0,
    offset: params[:offset]&.to_i || 0,
    query: params[:query] || ''
  ).values_at(:data, :metadata)
  render json: {
    data: data,
    metadata: 
  }
end

#update_from_table_editsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/payroll_calculations_controller.rb', line 27

def update_from_table_edits
  update_from_table_edits_params[:rows_edits].each do |row_edits|
    row_hash = row_edits[:rowHash]
    edits = row_edits[:edits]

    employee_id = current_company.employees.find_by!(employee_id: row_hash[:employee_id]).employee_id

    employee_payroll_calculation = EmployeePayrollCalculation.find_by!(
      employee_id: employee_id,
      payroll_calculation_template_id: row_hash[:payroll_calculation_template_id]
    )

    update_params = edits.slice('active')
    EmployeePayrollCalculation.update_procedure(
      employee_id: employee_id,
      payroll_calculation_template_id: row_hash[:payroll_calculation_template_id],
      active: update_params['active'].nil? ? employee_payroll_calculation.active : update_params['active'],
      erp_user_id: current_user.erp_user_id
    )
  end

  render json: {
    message: I18n.t('messages.payroll_calculation_updated')
  }
end