車種区分マスタ画面修正

This commit is contained in:
kin.rinzen 2025-09-12 20:43:46 +09:00
parent 464755b870
commit 2df716e781
12 changed files with 505 additions and 256 deletions

View File

@ -32,6 +32,8 @@ class PriceController extends Controller
if ($inputs['list']->total() > 0 && $inputs['page'] > $inputs['list']->lastPage()) {
return redirect()->route('prices');
}
$dataList = $this->getDataDropList();
$inputs = array_merge($inputs, $dataList);
return view('admin.prices.list', $inputs);
}
@ -39,48 +41,65 @@ class PriceController extends Controller
public function add(Request $request)
{
$inputs = [
'price_parkplaceid' => $request->input('price_parkplaceid'), // 駐車場所ID
'park_id' => $request->input('park_id'), // 駐輪場ID
'prine_name' => $request->input('prine_name'), // 商品名
'price_month' => $request->input('price_month',''), // 期間
'user_categoryid' => $request->input('user_categoryid'), // 利用者分類ID
'price' => $request->input('price'), // 駐輪料金(税込)
'psection_id' => $request->input('psection_id'), // 車種区分ID
'price_ptypeid' => $request->input('price_ptypeid'), // 駐輪分類ID
'pplace_id' => $request->input('pplace_id'), // 駐車車室ID
];
$dataList = $this->getDataDropList();
$inputs = array_merge($inputs, $dataList);
// POST の場合のみバリデーション + 保存
if ($request->isMethod('POST')) {
// ★ 1. 全角数字を半角に変換(例:123 → 123
$request->merge([
'pplace_id' => mb_convert_kana($request->input('pplace_id'), 'n'),
]);
// バリデーション
$validated = $request->validate([
'price_parkplaceid' => 'required|integer', // 駐車場所ID
'park_id' => 'required|integer', // 駐輪場ID
'prine_name' => 'required|string|max:255', // 商品名
'price_month' => 'nullable|integer', // 期間(月)
'user_categoryid' => 'required|integer', // 利用者分類ID
'price' => 'required|numeric|min:0', // 駐輪料金(税込)
'psection_id' => 'required|integer', // 車種区分ID
'price_ptypeid' => 'required|integer', // 駐輪分類ID
'pplace_id' => 'required|integer', // 駐車車室ID
], [
'pplace_id.integer' => '駐車車室ID は整数で入力してください。',
]);
// DB 登録
$type = false;
\DB::transaction(function () use ($inputs, &$type) {
\DB::transaction(function () use ($validated, &$type) {
$new = new Price();
$new->fill($inputs);
if( $new->save()){
$new->fill($validated);
if ($new->save()) {
$type = true;
}
});
// 結果
if ($type) {
$request->session()->flash('success', __('新しい成功を創造する。'));
return redirect()->route('prices');
return redirect()->route('prices')
->with('success', __('新しい成功を創造する。'));
} else {
$request->session()->flash('error', __('新しい作成に失敗しました'));
return redirect()->route('prices')
->with('error', __('新しい作成に失敗しました。'));
}
}
return view('admin.prices.add', $inputs);
// GET の場合 → 画面表示
$dataList = $this->getDataDropList();
return view('admin.prices.add', $dataList);
}
public function edit(Request $request, $pk ,$view=''){
public function edit(Request $request, $pk ,$view='')
{
$price = Price::getByPk($pk);
if (empty($pk) || empty($price)) {
abort('404');
abort(404);
}
$data = $price->getAttributes();
$dataList = $this->getDataDropList();
$data = array_merge($data, $dataList);
if ($request->isMethod('POST')) {
$type = false;
$requestAll = [
@ -95,111 +114,175 @@ class PriceController extends Controller
'pplace_id' => $request->input('pplace_id'),
];
$data = array_merge($data, $requestAll);
\DB::transaction(function () use ($data, &$type,$price) {
\DB::transaction(function () use ($data, &$type, $price) {
$price->fill($data);
$price->save();
$type = true;
});
if ($type) {
$request->session()->flash('success', __('更新に成功しました'));
return redirect()->route('prices');
return redirect()->route('prices')->with('success', __('更新に成功しました。'));
} else {
$request->session()->flash('error', __('更新に失敗しました'));
return redirect()->route('prices')->with('error', __('更新に失敗しました'));
}
}
if ($view != '') {
return view($view, $data);
}
return view('admin.prices.edit', $data);
}
public function delete(Request $request)
{
$arr_pk = $request->get('pk');
if ($arr_pk) {
if (Price::deleteByPk($arr_pk)) {
return redirect()->route('prices')->with('success', __("削除成功。"));
$ids = is_array($arr_pk) ? $arr_pk : [$arr_pk];
if (Price::deleteByPk($ids)) {
return redirect()->route('prices')->with('success', __("削除成功しました。"));
} else {
return redirect()->route('prices')->with('error', __('削除に失敗しました。'));
}
}
return redirect()->route('prices')->with('error', __('削除するユーザーを選択してください。'));
}
public static function deleteByPk($ids)
{
if (!is_array($ids)) {
$ids = [$ids];
}
return self::whereIn('price_parkplaceid', $ids)->delete();
}
public function export(Request $request)
{
$headers = array(
$headers = [
"Content-type" => "text/csv;charset=UTF-8",
'Content-Encoding: UTF-8',
"Content-Disposition" => "attachment; filename=file.csv",
"Pragma" => "no-cache",
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
"Expires" => "0"
);
$inputs = [
'isMethodPost' => 0,
'isExport' => 1,
'sort' => $request->input('sort', ''),
'sort_type' => $request->input('sort_type', ''),
];
$dataExport = Price::search($inputs);
$columns = array(
__('駐車場所ID'),// 0
__('商品名'),// 1
__('期間'),// 2
__('駐輪場ID'),// 3
__('駐輪場名'),// 3
__('車種区分ID'),// 5
__('車種区分'),// 6
__('駐輪分類ID'),// 7
__('駐輪分類'),// 8
__('利用者分類ID'),// 9
__('利用者分類'),// 10
__('駐車車室ID'),//11
__('駐輪料金(税込)'),// 12
);
$query = Price::query();
// 🚩 条件付きエクスポートpark_id
if ($request->filled('park_id')) {
$query->where('park_id', $request->input('park_id'));
}
// ソート
if ($request->filled('sort')) {
$query->orderBy($request->input('sort'), $request->input('sort_type', 'asc'));
}
$dataExport = $query->get();
$columns = [
__('駐車場所ID'),
__('商品名'),
__('期間'),
__('駐輪場ID'),
__('駐輪場名'),
__('車種区分ID'),
__('車種区分'),
__('駐輪分類ID'),
__('駐輪分類'),
__('利用者分類ID'),
__('利用者分類'),
__('駐車車室ID'),
__('駐輪料金(税込)'),
];
$filename = "駐輪場所、料金マスタ.csv";
$file = fopen($filename, 'w+');
fputcsv($file, $columns);
foreach ($dataExport as $items) {
fputcsv($file, array(
$items->price_parkplaceid,// 0
$items->prine_name, // 1
$items->price_month, // 2
$items->park_id, // 3
!empty($items->getPark())? $items->getPark()->park_name:'' ,// 4
$items->psection_id, // 5
!empty($items->getPSection())? $items->getPSection()->psection_subject:'',// 6
$items->price_ptypeid, // 7
!empty($items->getPType())? $items->getPType()->ptype_subject:'' ,// 8
$items->user_categoryid, //9
!empty($items->getUserType())? $items->getUserType()->print_name:'' ,//10
$items->pplace_id,// 11
$items->price, // 12
));
fputcsv($file, [
$items->price_parkplaceid,
$items->prine_name,
$items->price_month,
$items->park_id,
optional($items->getPark())->park_name,
$items->psection_id,
optional($items->getPSection())->psection_subject,
$items->price_ptypeid,
optional($items->getPType())->ptype_subject,
$items->user_categoryid,
optional($items->getUserType())->print_name,
$items->pplace_id,
$items->price,
]);
}
fclose($file);
return Response::download($filename, $filename, $headers);
}
public function import(Request $request)
{
$file = $request->file('file');
if(!empty($file)){
if (empty($file)) {
return redirect()->route('prices')->with('error', __('CSVファイルを選択してください。'));
}
$data = Utils::csvToArray($file);
$type = 1;
$type = true;
$msg = '';
$record = 0;
DB::beginTransaction();
try {
// 先清空数据(全置換仕様なら残す)
Price::query()->delete();
$col = 13;
$col = 13; // CSV 項目数
foreach ($data as $key => $items) {
$record = $key + 2;
if (count($items) == $col) {
$record = $key + 2; // エラー行番号(ヘッダ行を考慮)
// 項目数チェック
if (count($items) != $col) {
$type = false;
$msg = "行:{$record} 列数が一致しません。";
break;
}
// 必須チェック
if (empty($items[0])) { $type = false; $msg = "行:{$record} 駐車場所IDが未設定です。"; break; }
if (empty($items[1])) { $type = false; $msg = "行:{$record} 商品名が未設定です。"; break; }
if (empty($items[2])) { $type = false; $msg = "行:{$record} 期間が未設定です。"; break; }
if (empty($items[3])) { $type = false; $msg = "行:{$record} 駐輪場IDが未設定です。"; break; }
if (empty($items[5])) { $type = false; $msg = "行:{$record} 車種区分IDが未設定です。"; break; }
if (empty($items[7])) { $type = false; $msg = "行:{$record} 駐輪分類IDが未設定です。"; break; }
if (empty($items[9])) { $type = false; $msg = "行:{$record} 利用者分類IDが未設定です。"; break; }
if (empty($items[11])) { $type = false; $msg = "行:{$record} 駐車車室IDが未設定です。"; break; }
if (empty($items[12])) { $type = false; $msg = "行:{$record} 駐輪料金が未設定です。"; break; }
// マスタ存在チェック
if (!Park::where('park_id', $items[3])->exists()) {
$type = false; $msg = "行:{$record} 駐輪場IDが存在しません。"; break;
}
if (!Psection::where('psection_id', $items[5])->exists()) {
$type = false; $msg = "行:{$record} 車種区分IDが存在しません。"; break;
}
if (!Ptype::where('ptype_id', $items[7])->exists()) {
$type = false; $msg = "行:{$record} 駐輪分類IDが存在しません。"; break;
}
if (!Usertype::where('user_categoryid', $items[9])->exists()) {
$type = false; $msg = "行:{$record} 利用者分類IDが存在しません。"; break;
}
// TODO: 駐車車室ID チェックpplace_id
// 保存
$row = new Price();
$row->price_parkplaceid = $items[0];
$row->prine_name = $items[1];
@ -210,33 +293,26 @@ class PriceController extends Controller
$row->user_categoryid = $items[9];
$row->pplace_id = $items[11];
$row->price = $items[12];
if (!$row->save()) {
$type = 0;
$msg = '行:record型が一致しません。';
break;
}
} else {
$type = 0;
$msg = '行:record列数が一致しません。';
break;
$type = false; $msg = "行:{$record} データ保存に失敗しました。"; break;
}
}
} catch (\Exception $e) {
$msg = '行:record型が一致しません。';
$type = 0;
$type = false;
$msg = "行:{$record} 予期せぬエラー: ".$e->getMessage();
}
if ($type) {
DB::commit();
return redirect()->route('prices')->with('success', __('輸入成功'));
return redirect()->route('prices')->with('success', __('インポートが正常に完了しました。'));
} else {
DB::rollBack();
return redirect()->route('prices')->with('error', __($msg, ['record' => $record]));
}
} else {
return redirect()->route('prices')->with('error', __('あなたはcsvファイルを選択していません。'));
return redirect()->route('prices')->with('error', $msg);
}
}
public function info(Request $request, $id)
{
return $this->edit($request, $id, 'admin.prices.info');

View File

@ -11,20 +11,35 @@ class PsectionController extends Controller
// 一覧画面
public function list(Request $request)
{
// ソート順
$sort = $request->input('sort', 'psection_id');
$sort_type = $request->input('sort_type', 'asc');
$inputs = $request->all();
// ソート可能なカラム
$allowedSortColumns = ['psection_id', 'psection_subject'];
$query = Psection::query();
if (in_array($sort, ['psection_id', 'psection_subject'])) {
$query->orderBy($sort, $sort_type);
// ソート情報の取得
$sortColumn = $inputs['sort'] ?? 'psection_id';
$sortType = strtolower($inputs['sort_type'] ?? 'asc');
$query = \App\Models\Psection::query();
if (in_array($sortColumn, $allowedSortColumns, true)) {
if (!in_array($sortType, ['asc', 'desc'], true)) {
$sortType = 'asc';
}
$query->orderBy($sortColumn, $sortType);
}
$list = $query->get();
// ページネーション20件
$list = $query->paginate(20);
return view('admin.psection.list', compact('list', 'sort', 'sort_type'));
return view('admin.psection.list', [
'list' => $list,
'sort' => $sortColumn,
'sort_type' => $sortType,
]);
}
// 新規追加
public function add(Request $request)
{
@ -42,16 +57,26 @@ class PsectionController extends Controller
// 編集
public function edit(Request $request, $id)
{
// 主キーで検索(見つからない場合は 404
$psection = Psection::findOrFail($id);
if ($request->isMethod('post')) {
// バリデーション
$validated = $request->validate([
'psection_subject' => 'required|string|max:255',
]);
// データ更新
$psection->update($validated);
// 成功メッセージ & リダイレクト
return redirect()->route('psection')->with('success', '車種区分を更新しました');
}
// 編集画面を表示
return view('admin.psection.edit', compact('psection'));
}
}
// 詳細(info)
public function info(Request $request, $id)

View File

@ -21,6 +21,7 @@ class Price extends Model
protected $primaryKey = 'price_parkplaceid';
protected $fillable = [
'price_parkplaceid',
'prine_name',
'price_month',
'park_id',

View File

@ -18,20 +18,33 @@
@endif
<div class="card-body">
{{-- バリデーションエラー表示 --}}
@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 class="required">{{ __('駐車場所ID') }}</label>
</div>
<div class="form-group col-9">
<div class="input-group">
<input type="text" value="{{ $price_parkplaceid }}" name="price_parkplaceid"
class="form-control form-control-lg" readonly />
<input type="text"
name="price_parkplaceid"
value="{{ old('price_parkplaceid', $price_parkplaceid ?? '') }}"
class="form-control form-control-lg"
@if($isEdit) readonly @endif
placeholder="駐車場所ID" />
</div>
</div>
@endif
<!-- 商品名 -->
<div class="form-group col-3">
@ -39,8 +52,11 @@
</div>
<div class="form-group col-9">
<div class="input-group">
<input type="text" value="{{ $prine_name }}" name="prine_name"
class="form-control form-control-lg" />
<input type="text"
name="prine_name"
value="{{ old('prine_name', $prine_name ?? '') }}"
class="form-control form-control-lg"
placeholder="商品名" />
</div>
</div>
@ -53,13 +69,15 @@
<select name="price_month" class="form-control form-control-lg">
<option value="">{{ __('期間') }}</option>
@foreach(\App\Models\Price::PRICE_MONTH as $key => $item)
<option value="{{ $key }}" @if($key == $price_month) selected @endif>{{ $item }}</option>
<option value="{{ $key }}"
@if($key == old('price_month', $price_month ?? '')) selected @endif>
{{ $item }}
</option>
@endforeach
</select>
</div>
</div>
<!-- 駐輪場ID -->
<div class="form-group col-3">
<label class="required">{{ __('駐輪場名') }}</label>
@ -69,7 +87,10 @@
<select name="park_id" class="form-control form-control-lg">
<option value="">{{ __('駐輪場名') }}</option>
@foreach($parks as $key => $item)
<option value="{{ $key }}" @if($key == $park_id) selected @endif>{{ $item }}</option>
<option value="{{ $key }}"
@if($key == old('park_id', $park_id ?? '')) selected @endif>
{{ $item }}
</option>
@endforeach
</select>
</div>
@ -84,7 +105,10 @@
<select name="psection_id" class="form-control form-control-lg">
<option value="">{{ __('車種区分名') }}</option>
@foreach($psections as $key => $item)
<option value="{{ $key }}" @if($key == $psection_id) selected @endif>{{ $item }}</option>
<option value="{{ $key }}"
@if($key == old('psection_id', $psection_id ?? '')) selected @endif>
{{ $item }}
</option>
@endforeach
</select>
</div>
@ -100,14 +124,13 @@
<option value="">{{ __('駐輪分類名') }}</option>
@foreach($ptypes as $key => $item)
<option value="{{ $key }}"
@if(isset($price_ptypeid) && $key == $price_ptypeid) selected @endif>
@if($key == old('price_ptypeid', $price_ptypeid ?? '')) selected @endif>
{{ $item }}
</option>
@endforeach
</select>
</div>
</div>
<!-- 利用者分類 -->
<div class="form-group col-3">
<label class="required">{{ __('利用者分類') }}</label>
@ -117,50 +140,64 @@
<select name="user_categoryid" class="form-control form-control-lg">
<option value="">{{ __('利用者分類') }}</option>
@foreach($userTypes as $key => $item)
<option value="{{ $key }}" @if($key == $user_categoryid) selected @endif>{{ $item }}</option>
<option value="{{ $key }}"
@if($key == old('user_categoryid', $user_categoryid ?? '')) selected @endif>
{{ $item }}
</option>
@endforeach
</select>
</div>
</div>
<!-- 駐車車室ID -->
<div class="col-3">
<div class="form-group col-3">
<label class="required">{{ __('駐車車室ID') }}</label>
</div>
<div class="form-group col-9">
<div class="input-group">
<input type="text" value="{{ $pplace_id }}" name="pplace_id"
class="form-control form-control-lg" />
</div>
<input type="text"
name="pplace_id"
value="{{ old('pplace_id', $pplace_id ?? '') }}"
class="form-control form-control-lg"
placeholder="駐車車室ID">
@error('pplace_id')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<!-- 駐輪料金(税込) -->
<div class="col-3">
<div class="form-group col-3">
<label class="required">{{ __('駐輪料金(税込)') }}</label>
</div>
<div class="form-group col-9">
<div class="input-group">
<input type="text" value="{{ $price }}" name="price"
class="form-control form-control-lg" />
<input type="number"
name="price"
value="{{ old('price', $price ?? '') }}"
class="form-control form-control-lg"
placeholder="駐輪料金(税込)"
step="1" min="0" required>
</div>
</div>
</div>
{{-- 下部ボタン --}}
@if($isEdit)
{{-- 編集画面 --}}
{{-- 下部ボタン --}}
<div class="form-group col-12 d-flex gap-2 mt-4">
{{-- 登録ボタン --}}
<button type="submit" class="btn btn-lg btn-success mr-2">{{ __('登録') }}</button>
<form method="POST" action="{{ route('prices_delete', ['id' => $price_parkplaceid]) }}" class="d-inline">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-lg btn-danger">{{ __('削除') }}</button>
{{-- 削除ボタン(編集画面のみ表示) --}}
@if(!empty($price_parkplaceid))
</form>
<form method="POST" action="{{ route('prices_delete') }}"
onsubmit="return confirm('本当に削除しますか?')" class="d-inline-block mr-2">
@csrf
<input type="hidden" name="pk" value="{{ $price_parkplaceid }}">
<button type="submit" class="btn btn-lg btn-danger mr-2">{{ __('削除') }}</button>
</form>
@else
{{-- 新規画面 --}}
<button type="submit" class="btn btn-lg btn-success">{{ __('登録') }}</button>
@endif
</div>
</div>
<!-- /.card-body -->

View File

@ -26,7 +26,7 @@
<div class="card">
<form method="POST" action="{{ route('price_edit', ['id' => $price_parkplaceid]) }}" enctype="multipart/form-data">
@csrf
@method('PUT')
@include('admin.prices._form', ['isEdit' => true])
</form>
</div>

View File

@ -33,29 +33,93 @@
{{-- 各種アクションボタン群 --}}
<div class="container-fluid mb20">
{{-- 新規 --}}
<button type="button" class="btn btn-sm btn-default mr10"
onclick="location.href='{{ route('price_add') }}'">新規</button>
{{-- 削除 --}}
<button type="submit" class="btn btn-sm btn-default mr10"
form="form_delete" name="delete" id="delete"
form="form_delete" name="delete"
onclick="return confirm('選択した項目を削除しますか?');">削除</button>
<button type="submit" class="btn btn-sm btn-default mr10"
name="export_csv" id="export_csv"
action="{{ route('prices_export') }}">CSV出力</button>
{{-- CSV出力全件 or ソート条件付き)--}}
<form id="form_export" method="POST" action="{{ route('prices_export') }}" class="d-inline">
@csrf
<input type="hidden" name="sort" value="{{ $sort ?? '' }}">
<input type="hidden" name="sort_type" value="{{ $sort_type ?? '' }}">
<button type="submit" class="btn btn-sm btn-default mr10">CSV出力</button>
</form>
<button type="submit" class="btn btn-sm btn-default mr10"
name="import_csv" id="import_csv"
action="{{ route('prices_import') }}">インポート</button>
{{-- エクスポート(条件選択モーダル) --}}
<button type="button" class="btn btn-sm btn-default mr10" data-toggle="modal" data-target="#exportModal">
エクスポート
</button>
<button type="button" class="btn btn-sm btn-default mr10"
onclick="location.href='{{ route('prices_export') }}'">エクスポート</button>
{{-- インポート(モーダル) --}}
<button type="button" class="btn btn-sm btn-default mr10" data-toggle="modal" data-target="#importModal">
インポート
</button>
</div>
{{-- エクスポート用モーダル --}}
<div class="modal fade" id="exportModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form method="POST" action="{{ route('prices_export') }}">
@csrf
<div class="modal-body">
<p>エクスポートする駐輪場を選択してください。</p>
<div class="form-group row">
<label for="park_id" class="col-sm-4 col-form-label">駐輪場名</label>
<div class="col-sm-8">
<select name="park_id" id="park_id" class="form-control">
@foreach($parks as $id => $name)
<option value="{{ $id }}">{{ $name }}</option>
@endforeach
</select>
</div>
</div>
</div>
<div class="modal-footer justify-content-center">
<button type="submit" class="btn btn-primary w-25">OK</button>
<button type="button" class="btn btn-secondary w-25" data-dismiss="modal">キャンセル</button>
</div>
</form>
</div>
</div>
</div>
{{-- インポート用モーダル --}}
<div class="modal fade" id="importModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form method="POST" action="{{ route('prices_import') }}" enctype="multipart/form-data">
@csrf
<div class="modal-body">
<p>料金表をインポートします。ファイルを選択してください。</p>
<div class="form-group row">
<label for="import_file" class="col-sm-4 col-form-label">ファイル名</label>
<div class="col-sm-8">
<input type="file" name="file" id="import_file" class="form-control" required>
</div>
</div>
</div>
<div class="modal-footer justify-content-center">
<button type="submit" class="btn btn-primary w-25">OK</button>
<button type="button" class="btn btn-secondary w-25" data-dismiss="modal">キャンセル</button>
</div>
</form>
</div>
</div>
</div>
{{-- ページネーション --}}
<div class="container-fluid">
<div class="d-flex justify-content-end mb-3">
{{ $list->appends(['sort' => $sort ?? '', 'sort_type' => $sort_type ?? ''])->links('pagination') }}
{{ $list->appends([
'sort' => $sort ?? '',
'sort_type' => $sort_type ?? ''
])->links('pagination') }}
</div>
</div>

View File

@ -4,12 +4,12 @@
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-lg-6"><h1 class="m-0 text-dark">車種区分新規登録</h1></div>
<div class="col-lg-6"><h1 class="m-0 text-dark">新規登録</h1></div>
<div class="col-lg-6">
<ol class="breadcrumb float-sm-right text-sm">
<li class="breadcrumb-item"><a href="{{ url('/home') }}">ホーム</a></li>
<li class="breadcrumb-item"><a href="{{ route('psection') }}">車種区分マスタ</a></li>
<li class="breadcrumb-item active">新規</li>
<li class="breadcrumb-item active">新規登録</li>
</ol>
</div>
</div>
@ -18,7 +18,6 @@
<section class="content">
<div class="container-fluid">
{{-- 显示错误信息 --}}
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@ -39,9 +38,9 @@
<label>車種区分名 <span class="text-danger">*</span></label>
<input type="text" name="psection_subject" class="form-control" value="{{ old('psection_subject') }}" required>
</div>
<button type="submit" class="btn btn-primary"
<button type="submit" class="btn btn-lg btn-success"
onclick="return confirm('保存してもよろしいですか?');">登録</button>
<a href="{{ route('psection') }}" class="btn btn-secondary">戻る</a>
</form>
</div>
</section>

View File

@ -1,35 +1,69 @@
@extends('layouts.app')
@section('title', '車種区分新規登録')
@section('title', '車種区分マスタ 編集')
@section('content')
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-lg-6"><h1 class="m-0 text-dark">車種区分新規登録</h1></div>
<div class="col-lg-6">
<h1 class="m-0 text-dark">車種区分マスタ 編集</h1>
</div>
<div class="col-lg-6">
<ol class="breadcrumb float-sm-right text-sm">
<li class="breadcrumb-item"><a href="{{ url('/home') }}">ホーム</a></li>
<li class="breadcrumb-item"><a href="{{ route('home') }}">ホーム</a></li>
<li class="breadcrumb-item"><a href="{{ route('psection') }}">車種区分マスタ</a></li>
<li class="breadcrumb-item active">新規</li>
<li class="breadcrumb-item active">編集</li>
</ol>
</div>
</div>
</div>
</div>
<section class="content">
<div class="container-fluid">
<form method="POST" action="{{ route('psection_add') }}">
<div class="card">
<form method="POST" action="{{ route('psection_edit', ['id' => $psection->psection_id]) }}">
@csrf
<div class="form-group">
<label>車種区分ID <span class="text-danger">*</span></label>
<input type="number" name="psection_id" class="form-control" value="{{ old('psection_id') }}" required>
<div class="card-body">
{{-- 車種区分ID読み取り専用 --}}
<div class="form-group row">
<label class="col-3 col-form-label">車種区分ID</label>
<div class="col-9">
<input type="text" class="form-control" value="{{ $psection->psection_id }}" readonly>
</div>
<div class="form-group">
<label>車種区分名 <span class="text-danger">*</span></label>
<input type="text" name="psection_subject" class="form-control" value="{{ old('psection_subject') }}" required>
</div>
<button type="submit" class="btn btn-primary">登録</button>
<a href="{{ route('psection') }}" class="btn btn-secondary">戻る</a>
{{-- 車種区分名 --}}
<div class="form-group row">
<label class="col-3 col-form-label required">車種区分名</label>
<div class="col-9">
<input type="text" name="psection_subject"
class="form-control @error('psection_subject') is-invalid @enderror"
value="{{ old('psection_subject', $psection->psection_subject) }}">
@error('psection_subject')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
</div>
</div>
</div>
{{-- 下部ボタン --}}
<div class="text-left mb-3 ml-3">
{{-- 登録ボタン --}}
<button type="submit" class="btn btn-lg btn-success">登録</button>
{{-- 削除ボタン(同じ行に並べる) --}}
<form method="POST" action="{{ route('psection_delete', ['id' => $psection->psection_id]) }}" class="d-inline">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-lg btn-danger"
onclick="return confirm('この車種区分を削除しますか?');">削除</button>
</form>
</div>
</form>
</div>
</div>
</section>
@endsection

View File

@ -23,61 +23,51 @@
<section class="content">
<div class="container-fluid">
{{-- アクションボタン(市区マスタ準拠) --}}
{{-- アクションボタン --}}
<div class="mb-3">
<a href="{{ route('psection_add') }}" class="btn btn-sm btn-primary">新規</a>
<button type="submit" form="deleteForm" class="btn btn-sm btn-danger ml-2"
<a href="{{ route('psection_add') }}" class="btn btn-sm btn-default">新規</a>
<button type="submit" form="deleteForm" class="btn btn-sm btn-default ml-2"
onclick="return confirm('選択した区分を削除しますか?');">削除</button>
</div>
{{-- ページネーション --}}
<div class="d-flex justify-content-end mb-3">
{{ $list->appends([
'sort' => $sort ?? '',
'sort_type' => $sort_type ?? ''
])->links('pagination') }}
</div>
@if ($list->count() > 0)
<form id="deleteForm" method="POST" action="{{ route('psection_delete') }}">
@csrf
<div class="table-responsive">
<table class="table table-bordered table-hover" style="min-width:600px;">
<table class="table table-bordered dataTable text-nowrap">
<thead class="thead-light">
<tr>
{{-- 統合列:チェック + 編集(背景色は #faebd7 --}}
{{-- 統合列:チェック + 編集 --}}
<th style="width:140px;">
<input type="checkbox" onclick="$('input[name*=\'pk\']').prop('checked', this.checked);">
<span class="text-muted" style="font-weight:normal;"></span>
</th>
{{-- 表頭ソート対応ID / 名称) --}}
<th style="width:140px; text-align:center;">
<a href="{{ route('psection', ['sort' => 'id', 'direction' => ($sort=='id' && $direction=='asc')?'desc':'asc']) }}"
style="color:inherit; text-decoration:none;">
車種区分ID
@if($sort == 'id')
@if($direction == 'asc')
<span style="font-size:1.0em;">&#9650;</span>
@else
<span style="font-size:1.0em;">&#9660;</span>
@endif
@endif
</a>
{{-- ソート対象列 --}}
<th class="sorting {{ ($sort=='psection_id') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}"
sort="psection_id">
<span>車種区分ID</span>
</th>
<th style="text-align:center;">
<a href="{{ route('psection', ['sort' => 'subject', 'direction' => ($sort=='subject' && $direction=='asc')?'desc':'asc']) }}"
style="color:inherit; text-decoration:none;">
車種区分名
@if($sort == 'subject')
@if($direction == 'asc')
<span style="font-size:1.0em;">&#9650;</span>
@else
<span style="font-size:1.0em;">&#9660;</span>
@endif
@endif
</a>
<th class="sorting {{ ($sort=='psection_subject') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}"
sort="psection_subject">
<span>車種区分名</span>
</th>
</tr>
</thead>
<tbody>
<tbody class="bg-white">
@foreach ($list as $item)
<tr>
{{-- 統合セル:チェック + 編集(市区マスタの老書式に合わせる) --}}
{{-- 統合セル:チェック + 編集 --}}
<td style="background: #faebd7;">
<input type="checkbox" name="pk[]" value="{{ $item->psection_id }}">
<a href="{{ route('psection_edit', ['id' => $item->psection_id]) }}"
@ -99,4 +89,26 @@
@endif
</div>
</section>
{{-- ソート用スクリプト --}}
<script>
document.addEventListener("DOMContentLoaded", function() {
document.querySelectorAll("th.sorting, th.sorting_asc, th.sorting_desc").forEach(function(th) {
th.addEventListener("click", function() {
const sort = this.getAttribute("sort");
let sortType = "{{ $sort_type }}";
if ("{{ $sort }}" === sort) {
sortType = (sortType === "asc") ? "desc" : "asc";
} else {
sortType = "asc";
}
const url = new URL(window.location.href);
url.searchParams.set("sort", sort);
url.searchParams.set("sort_type", sortType);
window.location.href = url.toString();
});
});
});
</script>
@endsection

View File

@ -208,11 +208,11 @@
{{-- 下部ボタン --}}
@if($isEdit)
<button type="submit" class="btn btn-lg btn-success register">{{ __('保存') }}</button>
<button type="submit" class="btn btn-lg btn-secondary register">{{ __('戻る') }}</button>
@else
<button type="submit" class="btn btn-lg btn-success register">{{ __('登録') }}</button>
<button type="submit" class="btn btn-lg btn-danger register">{{ __('削除') }}</button>
@else
<button type="submit" class="btn btn-lg btn-success register">{{ __('登録') }}</button>
@endif
</div>

View File

@ -83,11 +83,11 @@
<div class="form-group col-12 text-left">
@if(isset($zone) && $zone->zone_id)
{{-- 編集画面 --}}
<button type="submit" class="btn btn-primary">保存</button>
<a href="{{ route('zones') }}" class="btn btn-secondary">戻る</a>
<button type="submit" class="btn btn-success">登録</button>
<a href="{{ route('zones') }}" class="btn btn-secondary">削除</a>
@else
{{-- 新規画面 --}}
<button type="submit" class="btn btn-success">登録</button>
<a href="{{ route('zones') }}" class="btn btn-secondary">削除</a>
@endif
</div>

View File

@ -183,7 +183,8 @@ Route::middleware('auth')->group(function () {
Route::match(['get', 'post'], '/admin/prices/info/{id}', [PriceController::class, 'info'])->name('price_info')->where(['id' => '[0-9]+']);
Route::match(['get', 'post'], '/admin/prices/delete', [PriceController::class, 'delete'])->name('prices_delete');
Route::match(['get', 'post'], '/admin/prices/import', [PriceController::class, 'import'])->name('prices_import');
Route::get('/admin/prices/export', [PriceController::class, 'export'])->name('prices_export');
// kin 修正
Route::post('/admin/prices/export', [PriceController::class, 'export'])->name('prices_export');
//車種区分マスタ
Route::match(['get', 'post'], '/admin/psection', [PsectionController::class, 'list'])->name('psection');