利用契約マスタの画面修正
All checks were successful
Deploy main / deploy (push) Successful in 24s

This commit is contained in:
kin.rinzen 2025-09-25 20:49:49 +09:00
parent c7db94973b
commit d1ddb474d8
9 changed files with 241 additions and 137 deletions

View File

@ -43,12 +43,14 @@ class TermsController extends Controller
{ {
if ($request->isMethod('post')) { if ($request->isMethod('post')) {
$validated = $request->validate([ $validated = $request->validate([
'city_id' => 'required|integer',
'terms_revision' => 'required|string|max:255', 'terms_revision' => 'required|string|max:255',
'terms_text' => 'required|string', 'terms_text' => 'required|string',
'start_date' => 'nullable|date', 'start_date' => 'nullable|date',
'use_flag' => 'required|in:0,1', 'use_flag' => 'required|in:0,1',
'memo' => 'nullable|string|max:255', 'memo' => 'nullable|string|max:255',
'city_id' => 'nullable|integer', 'terms_created_at' => 'nullable|date',
'operator_id' => 'nullable|integer', 'operator_id' => 'nullable|integer',
]); ]);
@ -62,7 +64,6 @@ class TermsController extends Controller
} }
// 編集画面・更新処理
public function edit(Request $request, $id) public function edit(Request $request, $id)
{ {
$term = Term::findOrFail($id); $term = Term::findOrFail($id);
@ -70,24 +71,27 @@ class TermsController extends Controller
if ($request->isMethod('post')) { if ($request->isMethod('post')) {
$validated = $request->validate([ $validated = $request->validate([
'city_id' => 'required|integer',
'terms_revision' => 'required|string|max:255', 'terms_revision' => 'required|string|max:255',
'terms_text' => 'required|string', 'terms_text' => 'required|string',
'start_date' => 'nullable|date', 'start_date' => 'nullable|date',
'use_flag' => 'required|in:0,1', 'use_flag' => 'required|in:0,1',
'memo' => 'nullable|string|max:255', 'memo' => 'nullable|string|max:255',
'city_id' => 'nullable|integer', 'terms_created_at'=> 'nullable|date',
'operator_id' => 'nullable|integer', 'operator_id' => 'nullable|integer',
]); ]);
$term->update($validated); $term->update($validated);
return redirect()->route('terms')->with('success', '利用規約が更新されました'); return redirect()->route('terms')->with('success', '利用規約が更新されました');
}
}
return view('admin.terms.edit', compact('term', 'cities')); return view('admin.terms.edit', compact('term', 'cities'));
} }
// 詳細表示 // 詳細表示
public function info($id) public function info($id)
{ {
@ -95,17 +99,24 @@ class TermsController extends Controller
return view('admin.terms.info', compact('term')); return view('admin.terms.info', compact('term'));
} }
// 削除処理(複数) // 削除処理(単一・複数対応
public function delete(Request $request) public function delete(Request $request)
{ {
$ids = $request->input('id', []); // 修正点:'pk' → 'id' $request->validate([
'pk' => 'required',
'pk.*' => 'integer', // 配列なら中身は整数
]);
if (!empty($ids)) { $arr_pk = $request->input('pk');
Term::destroy($ids); $ids = is_array($arr_pk) ? $arr_pk : [$arr_pk];
return redirect()->route('terms')->with('success', '削除しました');
$deleted = Term::destroy($ids);
if ($deleted > 0) {
return redirect()->route('terms')->with('success', __('削除成功しました。'));
} else {
return redirect()->route('terms')->with('error', __('削除に失敗しました。'));
} }
return redirect()->route('terms')->with('error', '削除対象が見つかりません');
} }
// CSVインポート // CSVインポート

View File

@ -34,4 +34,11 @@ class Term extends Model
{ {
return self::all(); return self::all();
} }
public static function deleteByPk($ids)
{
if (!is_array($ids)) {
$ids = [$ids];
}
return self::whereIn('terms_id', $ids)->delete();
}
} }

View File

@ -29,6 +29,7 @@ $('#checkbox_all').on('ifChecked ifUnchecked', function (event) {
}); });
$('#delete').on('click', function () { $('#delete').on('click', function () {
$.confirm({ $.confirm({
title: '確認ダイアログ。', title: '確認ダイアログ。',
content: '!※※※このレコードは他のテーブルから参照されている可能性があります。削除の際は十分注意してください。\n' + content: '!※※※このレコードは他のテーブルから参照されている可能性があります。削除の際は十分注意してください。\n' +
@ -160,3 +161,42 @@ $('.register').on('click', function (e) {
} }
}); });
}); });
// 編集画面専用 登録ボタン
$('#register_edit').on('click', function (e) {
e.preventDefault();
$.confirm({
title: '確認ダイアログ',
content: '登録してよろしいですか?',
buttons: {
ok: {
text: "はい",
btnClass: 'btn-primary',
action: function () {
$("#form_edit").submit(); // 更新処理
}
},
いいえ: function () {}
}
});
});
// 編集画面専用 削除ボタン
$('#delete_edit').on('click', function (e) {
e.preventDefault();
$.confirm({
title: '確認ダイアログ',
content: 'このレコードを削除してよろしいですか?',
buttons: {
ok: {
text: "はい",
btnClass: 'btn-primary',
action: function () {
$("#form_delete").submit(); // 削除処理
}
},
いいえ: function () {}
}
});
});

View File

@ -378,6 +378,15 @@ return [
'regular_class_6' => '定期種別6', 'regular_class_6' => '定期種別6',
'regular_class_12' => '定期種別12', 'regular_class_12' => '定期種別12',
'memo' => '備考', 'memo' => '備考',
// SWA-88
'city_id' => '市区ID',
'terms_revision' => 'リビジョン',
'terms_effective_date' => '契約内容有効日',
'terms_type' => '契約内容種別',
'terms_text' => '契約内容',
'use_flag' => '契約内容フラグ',
'terms_created_at' => '契約内容作成日',
'terms_updated_at' => '契約内容更新日',
], ],
]; ];

View File

@ -4,109 +4,142 @@
<div class="alert alert-danger alert-dismissible">{{ Session::get('error') }}</div> <div class="alert alert-danger alert-dismissible">{{ Session::get('error') }}</div>
@endif @endif
<section class="content">
<div class="container-fluid">
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
{{-- 利用契約ID --}} {{-- バリデーションエラー表示 --}}
@if($isEdit || $isInfo) @if ($errors->any())
<div class="row mb-3"> <div class="alert alert-danger">
<label class="col-md-2 col-form-label">利用契約ID</label> <ul class="mb-0">
<div class="col-md-10"> @foreach ($errors->all() as $error)
<input type="text" class="form-control" value="{{ $term->terms_id ?? '' }}" readonly> <li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="row">
@if($isEdit)
{{-- 利用規約ID --}}
<div class="col-3">
<label>{{ __('利用規約ID') }}</label>
</div>
<div class="form-group col-9">
<div class="input-group">
<input type="text" name="terms_id"
value="{{ old('terms_id', $term->terms_id ?? '') }}"
class="form-control form-control-lg"
readonly>
</div> </div>
</div> </div>
@endif @endif
{{-- 市区ID --}} {{-- 市区ID --}}
<div class="row mb-3"> <div class="col-3 form-group">
<label class="col-md-2 col-form-label">市区ID<span class="text-danger">*</span></label> <label class="required">{{ __('市区ID') }}</label>
<div class="col-md-10"> </div>
<select name="city_id" class="form-control" @if($isInfo) disabled @endif> <div class="col-9 form-group">
<option value="">都市を選択</option> <div class="input-group">
<select name="city_id" class="form-control form-control-lg">
<option value="">{{ __('都市を選択') }}</option>
@foreach($cities as $id => $city_name) @foreach($cities as $id => $city_name)
<option value="{{ $id }}" @if(old('city_id', $term->city_id ?? '') == $id) selected @endif>{{ $city_name }}</option> <option value="{{ $id }}" {{ old('city_id', $term->city_id ?? '') == $id ? 'selected' : '' }}>
{{ $city_name }}
</option>
@endforeach @endforeach
</select> </select>
</div> </div>
</div> </div>
{{-- 使用中 --}} {{-- 使用中 --}}
<div class="row mb-3"> <div class="col-3">
<label class="col-md-2 col-form-label">使用中</label> <label>{{ __('使用中') }}</label>
<div class="col-md-10 pt-2"> </div>
<div class="form-group col-9 pt-2">
<div class="form-check form-check-inline"> <div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="use_flag" value="1" @if(($term->use_flag ?? '') == 1) checked @endif @if($isInfo) disabled @endif> <input class="form-check-input" type="radio" name="use_flag" value="1"
<label class="form-check-label">使用中</label> {{ ($term->use_flag ?? '') == 1 ? 'checked' : '' }}>
<label class="form-check-label">{{ __('使用中') }}</label>
</div> </div>
<div class="form-check form-check-inline"> <div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="use_flag" value="0" @if(($term->use_flag ?? '') == 0) checked @endif @if($isInfo) disabled @endif> <input class="form-check-input" type="radio" name="use_flag" value="0"
<label class="form-check-label">過去のバージョン</label> {{ ($term->use_flag ?? '') == 0 ? 'checked' : '' }}>
</div> <label class="form-check-label">{{ __('過去のバージョン') }}</label>
</div> </div>
</div> </div>
{{-- リビジョン --}} {{-- リビジョン --}}
<div class="row mb-3"> <div class="col-3 form-group">
<label class="col-md-2 col-form-label">リビジョン<span class="text-danger">*</span></label> <label class="required">{{ __('リビジョン') }}</label>
<div class="col-md-10"> </div>
<input type="text" name="terms_revision" class="form-control" <div class="form-group col-9">
<div class="input-group">
<input type="text" name="terms_revision" class="form-control form-control-lg"
value="{{ old('terms_revision', $term->terms_revision ?? '') }}" value="{{ old('terms_revision', $term->terms_revision ?? '') }}"
@if($isInfo) readonly @endif> placeholder="{{ __('リビジョン') }}">
</div> </div>
</div> </div>
{{-- 契約内容 --}} {{-- 契約内容 --}}
<div class="row mb-3"> <div class="col-3 form-group">
<label class="col-md-2 col-form-label">契約内容<span class="text-danger">*</span></label> <label class="required">{{ __('契約内容') }}</label>
<div class="col-md-10"> </div>
<textarea name="terms_text" rows="5" class="form-control" @if($isInfo) readonly @endif>{{ old('terms_text', $term->terms_text ?? '') }}</textarea> <div class="form-group col-9">
<div class="input-group">
<textarea name="terms_text" rows="5" class="form-control form-control-lg"
placeholder="{{ __('契約内容') }}">{{ old('terms_text', $term->terms_text ?? '') }}</textarea>
</div> </div>
</div> </div>
{{-- 備考 --}} {{-- 備考 --}}
<div class="row mb-3"> <div class="col-3">
<label class="col-md-2 col-form-label">備考</label> <label>{{ __('備考') }}</label>
<div class="col-md-10"> </div>
<input type="text" name="memo" class="form-control" <div class="form-group col-9">
value="{{ old('memo', $term->memo ?? '') }}" @if($isInfo) readonly @endif> <div class="input-group">
<input type="text" name="memo" class="form-control form-control-lg"
value="{{ old('memo', $term->memo ?? '') }}"
placeholder="{{ __('備考') }}">
</div> </div>
</div> </div>
{{-- 使用開始日 --}} {{-- 使用開始日 --}}
<div class="row mb-3"> <div class="col-3">
<label class="col-md-2 col-form-label">使用開始日</label> <label>{{ __('使用開始日') }}</label>
<div class="col-md-10"> </div>
<div class="form-group col-9">
<div class="input-group">
<input type="date" name="start_date" class="form-control" <input type="date" name="start_date" class="form-control"
value="{{ old('start_date', $term->start_date ?? '') }}" @if($isInfo) readonly @endif> value="{{ old('start_date', isset($term->start_date) ? \Carbon\Carbon::parse($term->start_date)->format('Y-m-d') : '') }}"> </div>
</div> </div>
</div> </div>
{{-- 登録・削除 ボタン --}}
<div class="text-left mt-4"> {{-- 下部ボタン --}}
@if($isInfo) <div class="form-group col-12 d-flex gap-2 mt-4">
{{-- 詳細画面:編集に遷移 --}}
<a href="{{ route('terms_edit', ['id' => $term->terms_id]) }}" class="btn btn-lg btn-success"> {{-- 登録ボタン --}}
編集 @if($isEdit)
</a> {{-- 編集画面用 --}}
@else <button type="button" id="register_edit" class="btn btn-lg btn-success mr-2">
{{-- 新規/編集 共通フォーム --}} {{ __('登録') }}
<button type="submit" class="btn btn-lg btn-success">
{{ $isEdit ? '更新' : '登録' }}
</button> </button>
@else
{{-- 新規画面用 --}}
<button type="button" id="register" class="btn btn-lg btn-success mr-2 register">
{{ __('登録') }}
</button>
@endif
{{-- 編集時のみ削除可能 --}} {{-- 削除ボタン(編集時のみ表示) --}}
@if($isEdit && isset($term->terms_id)) @if($isEdit && !empty($term->terms_id))
<form id="delete-form" method="POST" action="{{ route('terms_delete', ['id' => $term->terms_id]) }}" style="display:inline;"> <button type="button" id="delete_edit" class="btn btn-lg btn-danger">
@csrf {{ __('削除') }}
@method('DELETE') </button>
<button type="submit" class="btn btn-lg btn-danger ml-2"
onclick="return confirm('削除してよろしいですか?')">削除</button>
</form>
@endif
@endif @endif
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</section>

View File

@ -6,7 +6,7 @@
<div class="container-fluid"> <div class="container-fluid">
<div class="row mb-2"> <div class="row mb-2">
<div class="col-sm-6"> <div class="col-sm-6">
<h1 class="m-0 text-dark">新規</h1> <h1 class="m-0 text-dark">新規登録</h1>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<ol class="breadcrumb float-sm-right text-sm"> <ol class="breadcrumb float-sm-right text-sm">
@ -21,15 +21,12 @@
<section class="content"> <section class="content">
<div class="container-fluid"> <div class="container-fluid">
<form action="{{ route('terms_add') }}" method="POST"> <form id="form_register" action="{{ route('terms_add') }}" method="POST">
@csrf @csrf
@include('admin.terms._form', [ @include('admin.terms._form', ['isEdit' => false])
'term' => null,
'cities' => $cities,
'isEdit' => false,
'isInfo' => false
])
</form> </form>
</div> </div>
</section> </section>
@endsection @endsection

View File

@ -21,15 +21,21 @@
<section class="content"> <section class="content">
<div class="container-fluid"> <div class="container-fluid">
<form action="{{ route('terms_edit', ['id' => $term->terms_id]) }}" method="POST"> {{-- 編集フォーム --}}
<form id="form_edit" action="{{ route('terms_edit', ['id' => $term->terms_id]) }}" method="POST">
@csrf @csrf
@include('admin.terms._form', [ @include('admin.terms._form', ['isEdit' => true])
'term' => $term,
'cities' => $cities,
'isEdit' => true,
'isInfo' => false
])
</form> </form>
<form id="form_delete" action="{{ route('terms_delete') }}" method="POST" style="display:none;">
@csrf
<input type="hidden" name="pk" value="{{ $term->terms_id }}">
</form>
</div> </div>
</section> </section>
@endsection @endsection

View File

@ -62,7 +62,7 @@
<form action="{{ route('terms_delete') }}" method="POST" id="form_delete"> <form action="{{ route('terms_delete') }}" method="POST" id="form_delete">
@csrf @csrf
<table class="table table-bordered dataTable text-nowrap"> <table class="table table-bordered dataTable text-nowrap">
<thead> <thead class="thead-light">
<tr> <tr>
{{-- チェック + 編集 用の1列 --}} {{-- チェック + 編集 用の1列 --}}
<th style="width:140px;" class="text-left"> <th style="width:140px;" class="text-left">

View File

@ -315,7 +315,8 @@ Route::middleware('auth')->group(function () {
Route::get('/terms/info/{id}', [TermsController::class, 'info']) Route::get('/terms/info/{id}', [TermsController::class, 'info'])
->where(['id' => '[0-9]+']) ->where(['id' => '[0-9]+'])
->name('terms_info'); ->name('terms_info');
Route::match(['get', 'post'], '/terms/delete', [TermsController::class, 'delete'])->name('terms_delete'); // Route::match(['get', 'post'], '/terms/delete', [TermsController::class, 'delete'])->name('terms_delete');
Route::post('/terms/delete', [TermsController::class, 'delete'])->name('terms_delete');
Route::post('/terms/import', [TermsController::class, 'import'])->name('terms_import'); Route::post('/terms/import', [TermsController::class, 'import'])->name('terms_import');
Route::get('/terms/export', [TermsController::class, 'export'])->name('terms_export'); Route::get('/terms/export', [TermsController::class, 'export'])->name('terms_export');