Class: PayrollPeriodsController
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/controllers/payroll_periods_controller.rb', line 81
def create
start_date = DateTime.parse(params[:start_date])
year = params[:payroll_year].to_i
current_company.generate_payroll_periods(
start_date: DateTime.parse(start_date.to_s),
year: year
)
render json: {
redirect_to: '/app/payroll/periods'
}
rescue ActiveRecord::RecordInvalid => e
render json: {
errors: e.record.errors,
message: e.record.errors.full_messages.join(', '),
redirect_to: '/app/payroll/periods/new'
}, status: :bad_request
end
|
#date_info ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# File 'app/controllers/payroll_periods_controller.rb', line 184
def date_info
date = Date.parse(params[:date]) || Date.today
payroll_period = current_company.payroll_period_for_date(date)
= payroll_period&.
render json: {
data: {
payroll_period: payroll_period.as_json(
methods: %i[
formatted
payroll_frequency_description
locked?
]
),
payroll_transaction_header:
}
}
rescue StandardError => e
render json: {
data: {}
}
end
|
#for_company ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/payroll_periods_controller.rb', line 15
def for_company
payroll_periods = PayrollTransactionView.select(
:payroll_transaction_header_id,
:payroll_period_id,
:payroll_year,
:period_no,
:period_start_date,
:period_end_date
).where(
company_id: params[:company_id]
).order(
:payroll_transaction_header_id
)
render json: {
payroll_periods: payroll_periods.as_json
}
end
|
45
46
47
48
49
50
51
52
53
|
# File 'app/controllers/payroll_periods_controller.rb', line 45
def form
render json: {
payroll_frequencies: TypesMaster.payroll_frequencies.as_json(
methods: %i[type_description]
),
latest_payroll_period_date: current_company.latest_payroll_period_date&.tomorrow,
payroll_frequency: current_company.payroll_frequency_type
}
end
|
#index ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/controllers/payroll_periods_controller.rb', line 55
def index
I18n.locale = params[:locale] if params[:locale]
payroll_periods = current_company.payroll_periods.order(start_date: :asc).to_a
payroll_periods.map! do |payroll_period|
frequency = TypesMaster.payroll_frequencies.find_by(type: payroll_period.frequency)
payroll_period.attributes.merge(
frequency_description: frequency&.type_description
)
end
render json: {
data: payroll_periods,
report_translations: TranslationService.new.translations
}
end
|
#options ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/payroll_periods_controller.rb', line 34
def options
render json: {
data: if @employee_id
current_company.payroll_periods_data(employee_id: @employee_id, group_by_year: true)
else
current_company.grouped_payroll_periods
end,
default: current_company.current_payroll_period
}
end
|
#payroll_cost_report ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'app/controllers/payroll_periods_controller.rb', line 162
def payroll_cost_report
I18n.locale = params[:locale] if params[:locale]
company_id = current_company_id
payroll_year = params[:payroll_year] || Time.now.year
payroll_period_no = params[:payroll_period_no] || current_company.current_payroll_period.period_no
report_type = ['S', 'D'].find { |type| type == params[:report_type] } || 'S'
data = ActiveRecord::Base.execute_procedure(
'pr_get_payroll_cost_report',
company_id,
payroll_year,
payroll_period_no,
report_type
)
render json: {
data: data,
report_translations: TranslationService.new.translations
}
end
|
#payroll_federal_withholding_report ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'app/controllers/payroll_periods_controller.rb', line 142
def payroll_federal_withholding_report
I18n.locale = params[:locale] if params[:locale]
company_id = current_company_id
payroll_year = params[:payroll_year] || Time.now.year
payroll_period_no = params[:payroll_period_no] || current_company.current_payroll_period.period_no
result = ActiveRecord::Base.execute_procedure(
'pr_get_payroll_federal_withholding_report',
company_id,
payroll_year,
payroll_period_no
)
render json: {
data: result,
report_translations: TranslationService.new.translations
}
end
|
#payroll_provincial_withholding_report ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'app/controllers/payroll_periods_controller.rb', line 122
def payroll_provincial_withholding_report
I18n.locale = params[:locale] if params[:locale]
company_id = current_company_id
payroll_year = params[:payroll_year] || Time.now.year
payroll_period_no = params[:payroll_period_no] || current_company.current_payroll_period.period_no
result = ActiveRecord::Base.execute_procedure(
'pr_get_payroll_provincial_withholding_report',
company_id,
payroll_year,
payroll_period_no
)
render json: {
data: result,
report_translations: TranslationService.new.translations
}
end
|
#payroll_reconciliation_report ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'app/controllers/payroll_periods_controller.rb', line 99
def payroll_reconciliation_report
I18n.locale = params[:locale] if params[:locale]
company_id = current_company_id
payroll_year = params[:payroll_year] || Time.now.year
payroll_period_no = params[:payroll_period_no] || current_company.current_payroll_period.period_no
report_type = params[:report_type] || 'S'
data = ActiveRecord::Base.execute_procedure(
'pr_get_payroll_reconciliation_report',
company_id,
payroll_year,
payroll_period_no,
report_type
)
render json: {
data: data,
report_translations: TranslationService.new.translations
}
end
|
#years ⇒ Object
70
71
72
73
74
75
76
77
78
79
|
# File 'app/controllers/payroll_periods_controller.rb', line 70
def years
years = PayrollPeriod.years_for_company(company_id: current_company.company_id)
current_year = Time.now.year
default_year = years.include?(current_year) ? current_year : years.last
render json: {
years: years,
default_year: default_year
}
end
|