This commit is contained in:
parent
b22cc34379
commit
f49a573d78
@ -15,7 +15,7 @@ class ReductionConfirmMasterController extends Controller
|
|||||||
* @param Request $request park_id をクエリパラメータで受け取る
|
* @param Request $request park_id をクエリパラメータで受け取る
|
||||||
* @return \Illuminate\View\View
|
* @return \Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function list(Request $request)
|
||||||
{
|
{
|
||||||
// park_id の検証
|
// park_id の検証
|
||||||
$request->validate([
|
$request->validate([
|
||||||
@ -47,7 +47,7 @@ class ReductionConfirmMasterController extends Controller
|
|||||||
)
|
)
|
||||||
->paginate(50);
|
->paginate(50);
|
||||||
|
|
||||||
return view('admin.reduction_confirm.index', [
|
return view('admin.reduction_confirm.list', [
|
||||||
'park' => $park,
|
'park' => $park,
|
||||||
'parkId' => $parkId,
|
'parkId' => $parkId,
|
||||||
'reductionData' => $reductionData,
|
'reductionData' => $reductionData,
|
||||||
@ -65,6 +65,8 @@ class ReductionConfirmMasterController extends Controller
|
|||||||
// バリデーション
|
// バリデーション
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'park_id' => 'required|integer|exists:park,park_id',
|
'park_id' => 'required|integer|exists:park,park_id',
|
||||||
|
'row_user_categoryid' => 'array',
|
||||||
|
'row_user_categoryid.*' => 'integer',
|
||||||
'reduction_confirm_type' => 'array',
|
'reduction_confirm_type' => 'array',
|
||||||
'reduction_confirm_type.*' => 'in:0,1,2',
|
'reduction_confirm_type.*' => 'in:0,1,2',
|
||||||
], [
|
], [
|
||||||
@ -75,27 +77,34 @@ class ReductionConfirmMasterController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$parkId = (int) $validated['park_id'];
|
$parkId = (int) $validated['park_id'];
|
||||||
$types = $validated['reduction_confirm_type'] ?? [];
|
|
||||||
|
|
||||||
// ログイン中のオペレータID取得
|
// ログイン中のオペレータID取得
|
||||||
$opeId = auth()->user()->ope_id ?? null;
|
$opeId = auth()->user()->ope_id ?? null;
|
||||||
|
|
||||||
|
// POST された配列は index ベースで来るため、row_user_categoryid のインデックスに合わせてマッピングする
|
||||||
|
$rowUserCategory = $request->input('row_user_categoryid', []);
|
||||||
|
$types = $request->input('reduction_confirm_type', []);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// トランザクションで更新処理を実行
|
DB::transaction(function () use ($parkId, $rowUserCategory, $types, $opeId) {
|
||||||
DB::transaction(function () use ($parkId, $types, $opeId) {
|
foreach ($rowUserCategory as $idx => $userCategoryId) {
|
||||||
foreach ($types as $userCategoryId => $type) {
|
if (!isset($types[$idx])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$type = (int) $types[$idx];
|
||||||
|
|
||||||
DB::table('reduction_confirm')
|
DB::table('reduction_confirm')
|
||||||
->where('park_id', $parkId)
|
->where('park_id', $parkId)
|
||||||
->where('user_categoryid', (int) $userCategoryId)
|
->where('user_categoryid', (int) $userCategoryId)
|
||||||
->update([
|
->update([
|
||||||
'reduction_confirm_type' => (int) $type,
|
'reduction_confirm_type' => $type,
|
||||||
'updated_at' => now(),
|
'updated_at' => now(),
|
||||||
'ope_id' => $opeId,
|
'ope_id' => $opeId,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return redirect()->route('reduction_confirm.index', ['park_id' => $parkId])
|
return redirect()->route('reduction_confirm.list', ['park_id' => $parkId])
|
||||||
->with('success', '減免確認マスタを更新しました。');
|
->with('success', '減免確認マスタを更新しました。');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::error('ReductionConfirm update failed', [
|
\Log::error('ReductionConfirm update failed', [
|
||||||
|
|||||||
@ -278,7 +278,7 @@ Route::middleware('auth')->group(function () {
|
|||||||
Route::match(['get', 'post'], '/usertypes/export', [UsertypeController::class, 'export'])->name('usertypes_export');
|
Route::match(['get', 'post'], '/usertypes/export', [UsertypeController::class, 'export'])->name('usertypes_export');
|
||||||
|
|
||||||
// 減免確認マスタ
|
// 減免確認マスタ
|
||||||
Route::get('/reduction-confirm-master', [ReductionConfirmMasterController::class, 'index'])->name('reduction_confirm.index');
|
Route::get('/reduction-confirm-master', [ReductionConfirmMasterController::class, 'list'])->name('reduction_confirm.list');
|
||||||
Route::post('/reduction-confirm-master', [ReductionConfirmMasterController::class, 'store'])->name('reduction_confirm.store');
|
Route::post('/reduction-confirm-master', [ReductionConfirmMasterController::class, 'store'])->name('reduction_confirm.store');
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user