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