質問編集履歴
1
コントローラーを追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -97,4 +97,117 @@
|
|
97
97
|
t.boolean "verification"
|
98
98
|
t.index ["user_id"], name: "index_attendances_on_user_id"
|
99
99
|
end
|
100
|
+
```
|
101
|
+
|
102
|
+
|
103
|
+
```rb
|
104
|
+
class AttendancesController < ApplicationController
|
105
|
+
|
106
|
+
before_action :set_user, only: [:edit_one_month]
|
107
|
+
before_action :logged_in_user, only: [:update, :edit_one_month]
|
108
|
+
before_action :admin_user, only: [:index,:destroy,:edit_basic_info]
|
109
|
+
before_action :set_one_month, only: [:edit_one_month]
|
110
|
+
|
111
|
+
UPDATE_ERROR_MSG = "勤怠登録に失敗しました。やり直してください。"
|
112
|
+
|
113
|
+
|
114
|
+
# 申請お知らせモーダル
|
115
|
+
|
116
|
+
def edit_overtime_notice
|
117
|
+
@user = User.find(params[:user_id])
|
118
|
+
@attendances = Attendance.where(indicater_check_superior: "申請中", indicater_check: @user.name).order(:user_id, :worked_on).group_by(&:user_id)
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
# お知らせモーダル更新
|
123
|
+
def update_overtime_notice
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
# 申請モーダル
|
130
|
+
def edit_overtime_request
|
131
|
+
@user = User.find(params[:user_id])
|
132
|
+
@attendance = Attendance.find(params[:id])
|
133
|
+
@superior = User.where(superior: true).where.not( id: current_user.id )
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
def update_overtime_request
|
138
|
+
@user = User.find(params[:user_id])
|
139
|
+
@attendance = Attendance.find(params[:id])
|
140
|
+
if @attendance.update_attributes(overtime_params)
|
141
|
+
flash[:success] = "残業申請を受け付けました"
|
142
|
+
redirect_to user_url(@user)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
def update
|
149
|
+
@user = User.find(params[:user_id])
|
150
|
+
@attendance = Attendance.find(params[:id])
|
151
|
+
if @attendance.started_at.nil?
|
152
|
+
if @attendance.update_attributes(started_at: Time.current.change(sec: 0))
|
153
|
+
flash[:info] = "おはようございます!"
|
154
|
+
else
|
155
|
+
flash[:danger] = UPDATE_ERROR_MSG
|
156
|
+
end
|
157
|
+
elsif @attendance.finished_at.nil?
|
158
|
+
if @attendance.update_attributes(finished_at: Time.current.change(sec: 0))
|
159
|
+
flash[:info] = "お疲れ様でした。"
|
160
|
+
else
|
161
|
+
flash[:danger] = UPDATE_ERROR_MSG
|
162
|
+
end
|
163
|
+
end
|
164
|
+
redirect_to @user
|
165
|
+
end
|
166
|
+
|
167
|
+
def edit_one_month
|
168
|
+
end
|
169
|
+
|
170
|
+
def update_one_month
|
171
|
+
ActiveRecord::Base.transaction do # トランザクションを開始します。
|
172
|
+
attendances_params.each do |id, item|
|
173
|
+
attendance = Attendance.find(id)
|
174
|
+
attendance.update_attributes!(item)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
flash[:success] = "1ヶ月分の勤怠情報を更新しました。"
|
178
|
+
redirect_to user_url(date: params[:date])
|
179
|
+
rescue ActiveRecord::RecordInvalid # トランザクションによるエラーの分岐です。
|
180
|
+
flash[:danger] = "無効な入力データがあった為、更新をキャンセルしました。"
|
181
|
+
redirect_to attendances_edit_one_month_user_url(date: params[:date])
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
private
|
191
|
+
# 1ヶ月分の勤怠情報を扱います。
|
192
|
+
def attendances_params
|
193
|
+
params.require(:user).permit(attendances: [:started_at, :finished_at, :note])[:attendances]
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
# 申請モーダルの情報
|
198
|
+
def overtime_params
|
199
|
+
params.require(:attendance).permit(:overtime_finished_at, :tomorrow, :overtime_work,:indicater_check,:indicater_check_superior)
|
200
|
+
end
|
201
|
+
|
202
|
+
# 申請お知らせモーダルの情報
|
203
|
+
def overtime_notice_params
|
204
|
+
params.require(:attendance).permit(:indicater_reply, :change, :verification, :indicater_check_superior)
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
end
|
212
|
+
|
100
213
|
```
|