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

View File

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

View File

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

View File

@ -21,15 +21,21 @@
<section class="content">
<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
@include('admin.terms._form', [
'term' => $term,
'cities' => $cities,
'isEdit' => true,
'isInfo' => false
])
@include('admin.terms._form', ['isEdit' => true])
</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>
</section>
@endsection

View File

@ -62,7 +62,7 @@
<form action="{{ route('terms_delete') }}" method="POST" id="form_delete">
@csrf
<table class="table table-bordered dataTable text-nowrap">
<thead>
<thead class="thead-light">
<tr>
{{-- チェック + 編集 用の1列 --}}
<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'])
->where(['id' => '[0-9]+'])
->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::get('/terms/export', [TermsController::class, 'export'])->name('terms_export');