Class: PayrollRunController
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
#process_step_1 ⇒ Object
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/controllers/payroll_run_controller.rb', line 18
def process_step_1
current_company.assign_attributes(
default_hours_per_week: params[:default_hours_per_week]
)
current_company.write_procedure(validate: false)
if params[:clone_timesheet] != 'no'
result = PayrollRun.process_step_1(
payroll_period_id: current_company.payroll_periods.find(
params[:period]
).payroll_period_id,
clone_from_payroll_period_id: current_company.payroll_periods.find(
params[:clone_timesheet_period_id]
).payroll_period_id,
create_default_hours_per_week: params[:clone_timesheet] === 'create_default_hours_per_week',
create_employees_default_hours_per_week: params[:clone_timesheet] === 'create_employees_default_hours_per_week',
default_hours_per_week: current_company.default_hours_per_week,
user_name: current_user.truncated_email
)
end
payroll_period_id_param = params[:period]&.to_i
payroll_period_id = if payroll_period_id_param == -1
params[:period_to_run_a_special_payroll]
else
payroll_period_id_param
end
special_pay = payroll_period_id_param == -1
= PayrollRun.process_step_2(
payroll_period_id: current_company.payroll_periods.find(payroll_period_id).payroll_period_id,
force_create_transaction: special_pay || current_company..count.zero?,
company: current_company,
user_name: current_user.truncated_email
)
period = current_company.payroll_periods.find(
params[:period]
)
raise 'No timesheets' unless period.has_timesheets?
PayrollTransactionHeader.find(
).update(
scheduled_deposit_date: params[:deposit_schedule_on_date]
)
render json: {
data: result,
redirect_to: "/app/payroll/run/#{}/review/timesheets"
}
end
|
#process_step_2 ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'app/controllers/payroll_run_controller.rb', line 96
def process_step_2
= current_company
.
.find(params[:payroll_transaction_header_id])
.payroll_period
= .
if .locked? && !current_user.has_permission?(Permission::Codes::RUN_SPECIAL_PAYROLL)
return render json: {
redirect_to: "/app/payroll/run/#{}/review/remunerations"
}
end
render json: {
redirect_to: "/app/payroll/run/#{}/review/remunerations"
}
end
|
#process_step_4 ⇒ Object
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'app/controllers/payroll_run_controller.rb', line 150
def process_step_4
= current_company..find(params[:payroll_transaction_header_id])
return render json: {}, status: :bad_request if .locked?
unless current_company.has_default_bank_account?
return render json: {
redirect_to: "/app/payroll/run/#{params[:payroll_transaction_header_id]}/summary",
message: 'Company does not have a default bank account'
}, status: :bad_request
end
PayrollRun.process_step_4(
payroll_transaction_header: ,
user_name: current_user.truncated_email
)
render json: {
redirect_to: '/app/payroll/transactions',
message: 'Payroll submitted for approval'
}
end
|
#recompute_payroll ⇒ Object
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# File 'app/controllers/payroll_run_controller.rb', line 174
def recompute_payroll
raise PermissionDeniedError unless current_user.has_permission?(Permission::Codes::RECALCULATE_PAYROLL)
= current_company..find(params[:payroll_transaction_header_id])
return render json: {}, status: :bad_request if .locked?
PayrollRun.compute_payroll(
transaction_header_id: params[:payroll_transaction_header_id],
reset_prior_to_generate: true,
payroll_transaction_detail_id: 0,
user_name: current_user.truncated_email
)
render json: {
message: I18n.t('messages.payroll_recomputed')
}
end
|
#step_1 ⇒ Object
13
14
15
16
|
# File 'app/controllers/payroll_run_controller.rb', line 13
def step_1
step_data = PayrollRun.step_1_data(company: current_company)
render json: step_data
end
|
#step_2 ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/controllers/payroll_run_controller.rb', line 72
def step_2
= params[:payroll_transaction_header_id]
= current_company
.
.find()
payroll_period = current_company
.
.find()
.payroll_period
render json: {
data: {
payroll_period: payroll_period.as_json(methods: %i[
locked?
has_employee_without_bank_account?
]),
company_name: current_company.company_name_e,
currencies: Currency.options,
revision_no: .revision_no
}
}
end
|
#step_3 ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'app/controllers/payroll_run_controller.rb', line 116
def step_3
= current_company..find(params[:payroll_transaction_header_id])
payroll_period = .payroll_period
default_employee_id = payroll_period.employee_ids.first
default_employee = Employee.find_employee_procedure(
company_id: current_company.company_id,
employee_id: default_employee_id
)
render json: {
data: {
payroll_period: payroll_period.as_json(methods: [:locked?]),
company_name: current_company.company_name_e,
default_employee: default_employee
}
}
end
|
#step_4 ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'app/controllers/payroll_run_controller.rb', line 134
def step_4
= current_company..find(params[:payroll_transaction_header_id])
step_data = PayrollRun.step_4_data(
transaction_header: ,
user_name: current_user.truncated_email
)
render json: {
step_data: step_data,
locked: .locked?,
sent_for_approval: .sent_for_approval?,
bank_account: current_company.bank_accounts.first.as_json(include: :currency),
has_default_bank_account: current_company.has_default_bank_account?
}
end
|