From c784f64e1e4e83d5419d16502084c61570953ceb Mon Sep 17 00:00:00 2001 From: Yuka Higashide Date: Wed, 10 Sep 2025 17:51:49 +0900 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=9C=9F=E5=A5=91=E7=B4=84=E5=B1=A5?= =?UTF-8?q?=E6=AD=B4=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/RegularContractController.php | 51 ++++++++++ .../views/regular_contract/history.blade.php | 92 +++++++++++++++++++ routes/web.php | 5 + 3 files changed, 148 insertions(+) create mode 100644 resources/views/regular_contract/history.blade.php diff --git a/app/Http/Controllers/RegularContractController.php b/app/Http/Controllers/RegularContractController.php index d294bf6..e22f916 100644 --- a/app/Http/Controllers/RegularContractController.php +++ b/app/Http/Controllers/RegularContractController.php @@ -76,6 +76,57 @@ class RegularContractController extends Controller ]); } + public function showHistory(Request $request) + { + $user_id = session('user_id'); + if (!$user_id) { + return redirect('/login'); + } + $user_name = DB::table('user')->where('user_id', $user_id)->value('user_name'); + + // 定期契約情報を取得(ページネーション付き) + $contracts_query = DB::table('regular_contract') + ->join('park', 'regular_contract.park_id', '=', 'park.park_id') + ->join('usertype', 'regular_contract.user_categoryid', '=', 'usertype.user_categoryid') + ->leftJoin('city', 'park.city_id', '=', 'city.city_id') + ->where('regular_contract.user_id', $user_id) + ->whereNotNull('regular_contract.contract_periods') + ->select( + 'regular_contract.contract_id', + 'park.park_name', + 'usertype.usertype_subject1', + 'regular_contract.contract_periods', + 'regular_contract.contract_periode', + 'regular_contract.enable_months', + 'regular_contract.park_id', + 'city.update_grace_period_start_date', + ) + ->orderBy('regular_contract.contract_id', 'desc'); + + // ページネーション(4件ずつ) + $contracts = $contracts_query->paginate(4); + + // grace日付加工 + $contracts->getCollection()->transform(function ($contract) { + $periode = $contract->contract_periode; + $grace_day = $contract->update_grace_period_start_date; + $ym = date('Y/m', strtotime($periode)); + $day = str_pad($grace_day, 2, '0', STR_PAD_LEFT); + $contract->periode_with_grace = $ym . '/' . $day; + return $contract; + }); + + \Log::info('契約履歴表示画面にアクセス', [ + 'user_id' => $user_id, + ]); + + return view('regular_contract.history', [ + 'active_menu' => 'SWC-6-1', // マイページメニューの選択状態用 + 'user_name' => $user_name, // ユーザー名(ヘッダー用) + 'contracts' => $contracts, + ]); + } + public function update($contract_id) { $user_id = session('user_id'); diff --git a/resources/views/regular_contract/history.blade.php b/resources/views/regular_contract/history.blade.php new file mode 100644 index 0000000..d86d8d1 --- /dev/null +++ b/resources/views/regular_contract/history.blade.php @@ -0,0 +1,92 @@ +@extends('layouts.app') +@section('content') +
+
+

契約履歴 > 定期契約履歴を見る

+
+
+ @if(count($contracts) > 0) + @foreach($contracts as $i => $contract) + @if($i % 2 == 0) +
+ @endif +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
定期契約ID{{ $contract->contract_id }}
駐輪場名{{ $contract->park_name }}
利用者区分{{ $contract->usertype_subject1 }}
開始日{{ \Carbon\Carbon::parse($contract->contract_periods)->format('Y/m/d') }}
月数{{ $contract->enable_months }}ヶ月
更新時期{{ $contract->periode_with_grace }}
+ @php + $has_receipt = DB::table('inv_publish')->where('contract_id', $contract->contract_id)->exists(); + @endphp + @if($has_receipt) + 領収書再発行 + @else + 領収書発行 + @endif +
+
+
+ @if($i % 2 == 1 || $i == count($contracts) - 1) +
+ @endif + @endforeach +
+ {{ $contracts->links('partials.paging') }} +
+ @else +
+

定期契約情報はありません。

+
+ @endif +
+ +
+
+
+ +@endsection + + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 6ff3109..53603af 100644 --- a/routes/web.php +++ b/routes/web.php @@ -128,6 +128,11 @@ Route::get('regular_contract/select_period/{contract_id}', [RegularContractContr ->name('regular_contract.select_period'); Route::post('regular_contract/update_period', [App\Http\Controllers\RegularContractController::class, 'updatePeriod']) ->name('regular_contract.update_period'); + +// 定期契約履歴 +Route::get('regular_contract/history', [RegularContractController::class, 'showHistory']) + ->name('regular_contract.history'); + // 空き待ち状況確認画面 Route::get('park_waitlist', [ParkWaitlistController::class, 'index']) ->name('park_waitlist.index'); -- 2.47.3