From 0a5e21cd9a21271cfaa78dbefc5f656f63e4d030 Mon Sep 17 00:00:00 2001 From: "OU.ZAIKOU" Date: Sun, 1 Feb 2026 02:21:00 +0900 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=B8=9B=E5=85=8D=E7=A2=BA=E8=AA=8D?= =?UTF-8?q?=E3=83=9E=E3=82=B9=E3=82=BF=E3=80=91=E5=88=9D=E7=89=88=E4=BD=9C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReductionConfirmMasterController.php | 111 +++++++++++++ app/Models/ReductionMaster.php | 48 ++++++ resources/views/admin/parks/edit.blade.php | 135 ++++++++-------- .../admin/reduction_confirm/_form.blade.php | 64 ++++++++ .../admin/reduction_confirm/index.blade.php | 152 ++++++++++++++++++ routes/web.php | 5 + 6 files changed, 449 insertions(+), 66 deletions(-) create mode 100644 app/Http/Controllers/Admin/ReductionConfirmMasterController.php create mode 100644 app/Models/ReductionMaster.php create mode 100644 resources/views/admin/reduction_confirm/_form.blade.php create mode 100644 resources/views/admin/reduction_confirm/index.blade.php diff --git a/app/Http/Controllers/Admin/ReductionConfirmMasterController.php b/app/Http/Controllers/Admin/ReductionConfirmMasterController.php new file mode 100644 index 0000000..90dacf7 --- /dev/null +++ b/app/Http/Controllers/Admin/ReductionConfirmMasterController.php @@ -0,0 +1,111 @@ +validate([ + 'park_id' => 'required|integer|exists:park,park_id', + ], [ + 'park_id.required' => '駐輪場IDは必須です。', + 'park_id.integer' => '駐輪場IDは整数である必要があります。', + 'park_id.exists' => '指定された駐輪場が見つかりません。', + ]); + + $parkId = (int) $request->input('park_id'); + + // 駐輪場情報を取得 + $park = Park::where('park_id', $parkId)->firstOrFail(); + + // reduction_confirm を主テーブルとして、usertype と JOIN して一覧を取得 + // WHERE park_id = ? で対象駐輪場のレコードのみ取得 + $reductionData = DB::table('reduction_confirm') + ->leftJoin('usertype', 'reduction_confirm.user_categoryid', '=', 'usertype.user_categoryid') + ->where('reduction_confirm.park_id', $parkId) + ->orderBy('reduction_confirm.user_categoryid', 'asc') + ->select( + 'reduction_confirm.park_id', + 'reduction_confirm.user_categoryid', + 'reduction_confirm.reduction_confirm_type', + 'usertype.usertype_subject1', + 'usertype.usertype_subject2', + 'usertype.usertype_subject3' + ) + ->paginate(50); + + return view('admin.reduction_confirm.index', [ + 'park' => $park, + 'parkId' => $parkId, + 'reductionData' => $reductionData, + ]); + } + + /** + * 減免確認情報を一括更新 + * + * @param Request $request + * @return \Illuminate\Http\RedirectResponse + */ + public function store(Request $request) + { + // バリデーション + $validated = $request->validate([ + 'park_id' => 'required|integer|exists:park,park_id', + 'reduction_confirm_type' => 'array', + 'reduction_confirm_type.*' => 'in:0,1,2', + ], [ + 'park_id.required' => '駐輪場IDは必須です。', + 'park_id.integer' => '駐輪場IDは整数である必要があります。', + 'park_id.exists' => '指定された駐輪場が見つかりません。', + 'reduction_confirm_type.*.in' => '減免確認種別は0, 1, 2 のいずれかである必要があります。', + ]); + + $parkId = (int) $validated['park_id']; + $types = $validated['reduction_confirm_type'] ?? []; + + // ログイン中のオペレータID取得 + $opeId = auth()->user()->ope_id ?? null; + + try { + // トランザクションで更新処理を実行 + DB::transaction(function () use ($parkId, $types, $opeId) { + foreach ($types as $userCategoryId => $type) { + DB::table('reduction_confirm') + ->where('park_id', $parkId) + ->where('user_categoryid', (int) $userCategoryId) + ->update([ + 'reduction_confirm_type' => (int) $type, + 'updated_at' => now(), + 'ope_id' => $opeId, + ]); + } + }); + + return redirect()->route('reduction_confirm.index', ['park_id' => $parkId]) + ->with('success', '減免確認マスタを更新しました。'); + } catch (\Exception $e) { + \Log::error('ReductionConfirm update failed', [ + 'park_id' => $parkId, + 'error' => $e->getMessage(), + ]); + + return back()->withErrors(['error' => '更新に失敗しました。管理者にお問い合わせください。']) + ->withInput(); + } + } +} + diff --git a/app/Models/ReductionMaster.php b/app/Models/ReductionMaster.php new file mode 100644 index 0000000..e199364 --- /dev/null +++ b/app/Models/ReductionMaster.php @@ -0,0 +1,48 @@ +where('user_categoryid', $userCategoryId) + ->first(); + } + + /** + * レコード保存時に operator_id を自動設定 + */ + public static function boot() + { + parent::boot(); + self::saving(function (ReductionMaster $model) { + if (!isset($model->operator_id) || $model->operator_id === null) { + $model->operator_id = Auth::user()->ope_id ?? null; + } + }); + } +} diff --git a/resources/views/admin/parks/edit.blade.php b/resources/views/admin/parks/edit.blade.php index eb0718b..33efd9a 100644 --- a/resources/views/admin/parks/edit.blade.php +++ b/resources/views/admin/parks/edit.blade.php @@ -2,76 +2,79 @@ @section('title', '駐輪場マスタ 編集') @section('content') -{{-- ▼ パンくず --}} -
-
-
-
-

編集

-
-
- -
+ {{-- ▼ パンくず --}} +
+
+
+
+

編集

+
+
+ +
+
+
-
-
-{{-- ▼ 編集フォーム --}} -
-
- @csrf - @method('PUT') + {{-- ▼ 編集フォーム --}} +
+ + @csrf + @method('PUT') -
- {{-- ▼ ボタンエリア(上部) --}} -
- - 減免確認編集 - 駐輪状況編集 - -
+
+ {{-- ▼ ボタンエリア(上部) --}} + +
+
+ {{-- ▼ 入力フォーム --}} + @include('admin.parks._form') + + {{-- ▼ フッター(下部ボタン) --}} + +
+
-
- {{-- ▼ 入力フォーム --}} - @include('admin.parks._form') - {{-- ▼ フッター(下部ボタン) --}} - -
- -
+ + - - + + + - - - - - -@endsection \ No newline at end of file + +@endsection diff --git a/resources/views/admin/reduction_confirm/_form.blade.php b/resources/views/admin/reduction_confirm/_form.blade.php new file mode 100644 index 0000000..c23dd7a --- /dev/null +++ b/resources/views/admin/reduction_confirm/_form.blade.php @@ -0,0 +1,64 @@ +{{-- 減免確認マスタテーブル行(各利用者分類) --}} +@php + // reduction_confirm テーブルから取得したレコード + $userCategoryId = $row->user_categoryid; + $checkType = $row->reduction_confirm_type; + $oldCheckType = old("reduction_confirm_type.$userCategoryId", $checkType); + + // 学生分類かどうかを判定 + $isStudent = $row->usertype_subject1 === '学生'; + $rowClass = $isStudent ? 'table-secondary' : ''; + $isDisabled = $isStudent; +@endphp + + + {{ $userCategoryId }} + {{ $row->usertype_subject1 ?? '-' }} + {{ $row->usertype_subject2 ?? '-' }} + {{ $row->usertype_subject3 ?? '-' }} + +
+ {{-- 確認しない(0) --}} +
+ + +
+ + {{-- 年1回(1) --}} +
+ + +
+ + {{-- 毎更新時(2) --}} +
+ + +
+
+ + diff --git a/resources/views/admin/reduction_confirm/index.blade.php b/resources/views/admin/reduction_confirm/index.blade.php new file mode 100644 index 0000000..7e03548 --- /dev/null +++ b/resources/views/admin/reduction_confirm/index.blade.php @@ -0,0 +1,152 @@ +@extends('layouts.app') +@section('title', '減免確認マスタ') + +@section('content') + +
+
+
+
+

減免確認マスタ

+
+
+ +
+
+
+
+ +
+
+ {{-- エラーメッセージ表示 --}} + @if ($errors->any()) + + @endif + + {{-- 成功メッセージ表示 --}} + @if (session('success')) + + @endif + + +
+
+
+

駐輪場情報

+
+
+
+
+ +
+
+
+ {{ $park->park_name ?? '' }} +
+
+
+
+ +
+
+ + +{{-- +
+ 全 {{ $list->total() }} 件中 {{ $list->firstItem() }}〜{{ $list->lastItem() }} 件を表示 +
+
+ {{ $list->appends(keepUserListQuery())->links('pagination') }} +
+--}} + +
+ + +
+
+ {{-- 登録ボタン --}} +
+ +
+ + @csrf + + + +
+ + + + + + + + + + + + @forelse ($reductionData as $row) + @include('admin.reduction_confirm._form', ['row' => $row]) + @empty + + + + @endforelse + +
利用者分類分類名1分類名2分類名3減免確認種別
+ 利用者分類がありません。 +
+
+
+
+ +
+ + +@endsection diff --git a/routes/web.php b/routes/web.php index b1e971e..2608ba5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -42,6 +42,7 @@ use App\Http\Controllers\Admin\MailTemplateController; use App\Http\Controllers\Admin\InvSettingController; use App\Http\Controllers\Admin\ZoneController; use App\Http\Controllers\Admin\PplaceController; +use App\Http\Controllers\Admin\ReductionConfirmMasterController; use App\Http\Controllers\HomeController; use App\Http\Controllers\Auth\EmailOtpController; @@ -276,6 +277,10 @@ Route::middleware('auth')->group(function () { Route::match(['get', 'post'], '/usertypes/import', [UsertypeController::class, 'import'])->name('usertypes_import'); 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::post('/reduction-confirm-master', [ReductionConfirmMasterController::class, 'store'])->name('reduction_confirm.store'); + // 契約者一覧