diff --git a/app/Http/Controllers/Admin/UsertypeController.php b/app/Http/Controllers/Admin/UsertypeController.php index 424b3a1..0b53e66 100644 --- a/app/Http/Controllers/Admin/UsertypeController.php +++ b/app/Http/Controllers/Admin/UsertypeController.php @@ -15,20 +15,35 @@ class UsertypeController extends Controller { public function list(Request $request) { + $sortable = ['user_categoryid', 'sort_order', 'usertype_subject1', 'usertype_subject2', 'usertype_subject3', 'print_name', 'usertype_remarks']; + $sort = $request->input('sort', 'user_categoryid'); + if (!in_array($sort, $sortable, true)) { + $sort = 'user_categoryid'; + } + $sortType = strtolower($request->input('sort_type', 'asc')); + if (!in_array($sortType, ['asc', 'desc'], true)) { + $sortType = 'asc'; + } $inputs = [ - 'isMethodPost' => 0, + 'isMethodPost' => $request->isMethod('post') ? 1 : 0, 'isExport' => 0, - 'sort' => $request->input('sort', ''), - 'sort_type' => $request->input('sort_type', ''), - 'page' => $request->get('page', 1), - + 'sort' => $sort, + 'sort_type' => $sortType, + 'page' => (int) $request->get('page', 1), ]; - $inputs['isMethodPost'] = $request->isMethod('post'); - $inputs['list'] = Usertype::search($inputs); - if ($inputs['list']->total() > 0 && $inputs['page'] > $inputs['list']->lastPage()) { + $filters = [ + 'filter_sort_order' => $request->input('filter_sort_order', ''), + 'filter_category_name1' => $request->input('filter_category_name1', ''), + 'filter_category_name2' => $request->input('filter_category_name2', ''), + 'filter_category_name3' => $request->input('filter_category_name3', ''), + ]; + $searchParams = array_merge($inputs, $filters); + $viewData = $searchParams; + $viewData['list'] = Usertype::search($searchParams); + if ($viewData['list']->total() > 0 && $viewData['page'] > $viewData['list']->lastPage()) { return redirect()->route('usertypes'); } - return view('admin.usertypes.list', $inputs); + return view('admin.usertypes.list', $viewData); } public function add(Request $request) @@ -36,9 +51,9 @@ class UsertypeController extends Controller // 画面に戻すための初期値 $viewData = [ 'sort_order' => old('sort_order', ''), - 'category_name1' => old('category_name1', ''), - 'category_name2' => old('category_name2', ''), - 'category_name3' => old('category_name3', ''), + 'usertype_subject1' => old('usertype_subject1', ''), + 'usertype_subject2' => old('usertype_subject2', ''), + 'usertype_subject3' => old('usertype_subject3', ''), 'print_name' => old('print_name', ''), 'usertype_money' => old('usertype_money', ''), 'usertype_remarks' => old('usertype_remarks', ''), @@ -50,9 +65,9 @@ class UsertypeController extends Controller // 入力値をまとめる $inputs = [ 'sort_order' => $request->input('sort_order'), - 'category_name1' => $request->input('category_name1'), - 'category_name2' => $request->input('category_name2'), - 'category_name3' => $request->input('category_name3'), + 'usertype_subject1' => $request->input('usertype_subject1'), + 'usertype_subject2' => $request->input('usertype_subject2'), + 'usertype_subject3' => $request->input('usertype_subject3'), 'print_name' => $request->input('print_name'), 'usertype_money' => $request->input('usertype_money'), 'usertype_remarks' => $request->input('usertype_remarks'), @@ -61,9 +76,9 @@ class UsertypeController extends Controller // バリデーションルール(最小限) $rules = [ 'sort_order' => 'nullable|integer', - 'category_name1' => 'nullable|string|max:255', - 'category_name2' => 'nullable|string|max:255', - 'category_name3' => 'nullable|string|max:255', + 'usertype_subject1' => 'nullable|string|max:255', + 'usertype_subject2' => 'nullable|string|max:255', + 'usertype_subject3' => 'nullable|string|max:255', 'print_name' => 'required|string|max:255', 'usertype_money' => 'nullable|string|max:255', 'usertype_remarks' => 'nullable|string|max:255', @@ -115,9 +130,9 @@ class UsertypeController extends Controller // ▼ 内蔵バリデーション(FormRequest を使わない) $rules = [ 'sort_order' => 'nullable|integer', - 'category_name1' => 'nullable|string|max:255', - 'category_name2' => 'nullable|string|max:255', - 'category_name3' => 'nullable|string|max:255', + 'usertype_subject1' => 'nullable|string|max:255', + 'usertype_subject2' => 'nullable|string|max:255', + 'usertype_subject3' => 'nullable|string|max:255', 'print_name' => 'required|string|max:255', 'usertype_money' => 'nullable|string|max:255', 'usertype_remarks' => 'nullable|string|max:255', @@ -141,9 +156,9 @@ class UsertypeController extends Controller // fill するフィールドだけを明示したい場合は only(...) で絞ってもOK $usertype->fill([ 'sort_order' => $data['sort_order'] ?? null, - 'category_name1' => $data['category_name1'] ?? null, - 'category_name2' => $data['category_name2'] ?? null, - 'category_name3' => $data['category_name3'] ?? null, + 'usertype_subject1' => $data['usertype_subject1'] ?? null, + 'usertype_subject2' => $data['usertype_subject2'] ?? null, + 'usertype_subject3' => $data['usertype_subject3'] ?? null, 'print_name' => $data['print_name'] ?? null, 'usertype_money' => $data['usertype_money'] ?? null, 'usertype_remarks' => $data['usertype_remarks'] ?? null, @@ -197,15 +212,16 @@ class UsertypeController extends Controller public function export(Request $request) { - - $headers = array( - "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" - ); + $timestamp = now()->format('YmdHis'); + $filename = "利用者分類マスタ{$timestamp}.csv"; + $filePath = storage_path("app/{$filename}"); + $headers = [ + 'Content-Type' => 'text/csv; charset=UTF-8', + 'Content-Encoding' => 'UTF-8', + 'Pragma' => 'no-cache', + 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', + 'Expires' => '0', + ]; $inputs = [ 'isMethodPost' => 0, 'isExport' => 1, @@ -221,8 +237,7 @@ class UsertypeController extends Controller __('適用料率'),// 2 __('備考'),// 3 ); - $filename = "利用者分類マスタ.csv"; - $file = fopen($filename, 'w+'); + $file = fopen($filePath, 'w+'); fputcsv($file, $columns); foreach ($dataExport as $items) { fputcsv( @@ -236,7 +251,7 @@ class UsertypeController extends Controller ); } fclose($file); - return Response::download($filename, $filename, $headers); + return Response::download($filePath, $filename, $headers)->deleteFileAfterSend(true); } public function import(Request $request) diff --git a/app/Models/Usertype.php b/app/Models/Usertype.php index ac73bd2..b2b28ae 100644 --- a/app/Models/Usertype.php +++ b/app/Models/Usertype.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Utils; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Auth; @@ -15,9 +16,14 @@ class Usertype extends Model protected $primaryKey = 'user_categoryid'; protected $fillable = [ + 'sort_order', + 'usertype_subject1', + 'usertype_subject2', + 'usertype_subject3', 'print_name', 'usertype_money', - 'usertype_remarks' + 'usertype_remarks', + 'operator_id', ]; public static function boot() @@ -30,20 +36,37 @@ class Usertype extends Model public static function search($inputs) { - $list = self::query(); - if ($inputs['isMethodPost']) { - + $query = self::query(); + + if (!empty($inputs['filter_sort_order'])) { + $query->where('sort_order', $inputs['filter_sort_order']); } - // Sort - if ($inputs['sort']) { - $list->orderBy($inputs['sort'], $inputs['sort_type']); + if (!empty($inputs['filter_category_name1'])) { + $query->where('usertype_subject1', 'like', '%' . $inputs['filter_category_name1'] . '%'); } - if ($inputs['isExport']){ - $list = $list->get(); - }else{ - $list = $list->paginate(Utils::item_per_page); + if (!empty($inputs['filter_category_name2'])) { + $query->where('usertype_subject2', 'like', '%' . $inputs['filter_category_name2'] . '%'); } - return $list; + if (!empty($inputs['filter_category_name3'])) { + $query->where('usertype_subject3', 'like', '%' . $inputs['filter_category_name3'] . '%'); + } + + $sortable = ['user_categoryid', 'sort_order', 'usertype_subject1', 'usertype_subject2', 'usertype_subject3', 'print_name', 'usertype_remarks']; + $sortColumn = $inputs['sort'] ?? 'user_categoryid'; + if (!in_array($sortColumn, $sortable, true)) { + $sortColumn = 'user_categoryid'; + } + + $direction = strtolower($inputs['sort_type'] ?? 'asc'); + if (!in_array($direction, ['asc', 'desc'], true)) { + $direction = 'asc'; + } + + $query->orderBy($sortColumn, $direction); + + return !empty($inputs['isExport']) + ? $query->get() + : $query->paginate(Utils::item_per_page); } public static function getByPk($pk) diff --git a/resources/views/admin/usertypes/_form.blade.php b/resources/views/admin/usertypes/_form.blade.php index 0591f4f..0a03880 100644 --- a/resources/views/admin/usertypes/_form.blade.php +++ b/resources/views/admin/usertypes/_form.blade.php @@ -1,105 +1,179 @@ -
- @if(Session::has('success')) - - @elseif(Session::has('error')) -
- -

{{__('誤差')}}:

- {!! Session::get('error') !!} -
- @elseif(isset($errorMsg)) -
- -

{{__('誤差')}}:

- {!! $errorMsg !!} +
+
+ @if(Session::has('success')) + + @elseif(Session::has('error')) + + @elseif(isset($errorMsg)) + + @endif +
+ + @if($isInfo || $isEdit) +
+ @if($isInfo) + {{ __('登録') }} + {{ __('編集') }} + @else + + @endif
@endif -
-
-
-
-
-
- @if($isInfo) - {{__('登録')}} - {{__('編集')}} - @else - - - @endif +
+
+ @if($isInfo || $isEdit) +
+ +
+ +
- @csrf - - - @if($isInfo || $isEdit) - - - - - @endif - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{__('validation.attributes.user_categoryid')}} - -
{{__('分類名')}} - -
{{__('適用料率')}} - -
{{__('備考')}} - -
{{__('ソートオーダー')}} - -
{{__('分類名1')}} - -
{{__('分類名2')}} - -
{{__('分類名3')}} - -
-
- @if($isInfo) - {{__('登録')}} - {{__('編集')}} - @else - - - @endif + @endif + +
+ +
+
- +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
-
\ No newline at end of file + +
+ @if($isInfo) + {{ __('登録') }} + {{ __('編集') }} + @else + + @if($isEdit) + + @endif + @endif +
+
+ +@push('styles') + +@endpush + +@push('scripts') + @once + + @endonce +@endpush \ No newline at end of file diff --git a/resources/views/admin/usertypes/add.blade.php b/resources/views/admin/usertypes/add.blade.php index c7926c9..8cab9eb 100644 --- a/resources/views/admin/usertypes/add.blade.php +++ b/resources/views/admin/usertypes/add.blade.php @@ -1,6 +1,5 @@ - @extends('layouts.app') -@section('title', '[東京都|〇〇駐輪場] 利用者分類マスタ') +@section('title', '利用者分類マスタ') @section('content') @@ -8,14 +7,13 @@
-

[東京都|〇〇駐輪場] 利用者分類マスタ

+

新規

@@ -30,14 +28,15 @@
-
-
- - - - @include('admin.usertypes._form',['isEdit'=>0,'isInfo'=>0]) -
-
+
+ @csrf +
+
+ +
+ @include('admin.usertypes._form',['isEdit'=>0,'isInfo'=>0]) +
+
@@ -45,3 +44,38 @@ @endsection + +@push('scripts') + +@endpush diff --git a/resources/views/admin/usertypes/list.blade.php b/resources/views/admin/usertypes/list.blade.php index 171c513..ea7ef23 100644 --- a/resources/views/admin/usertypes/list.blade.php +++ b/resources/views/admin/usertypes/list.blade.php @@ -1,5 +1,5 @@ @extends('layouts.app') -@section('title', '[東京都|〇〇駐輪場] 利用者分類マスタ') +@section('title', '利用者分類マスタ') @section('content')
@@ -16,29 +16,110 @@
- - +
-
+ @csrf - - + + +
+
+ {{ __('絞り込み') }} +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+ + +
+
+
- -
-
-
- {{__('新規')}} - - -
-
- {{ $list->appends(['sort' => $sort, 'sort_type' => $sort_type])->links('pagination') }} -
+
+ @csrf + + + + + + +
+
+
+ {{ __('新規') }} + + +
+
+ {{ $list->appends([ + 'sort' => $sort, + 'sort_type' => $sort_type, + 'filter_sort_order' => $filter_sort_order ?? '', + 'filter_category_name1' => $filter_category_name1 ?? '', + 'filter_category_name2' => $filter_category_name2 ?? '', + 'filter_category_name3' => $filter_category_name3 ?? '', + ])->links('pagination') }}
@@ -64,34 +145,75 @@
@csrf -
- +
+ @php + $currentSort = $sort ?? ''; + $currentDir = strtolower($sort_type ?? 'asc'); + if (!in_array($currentDir, ['asc', 'desc'], true)) { + $currentDir = 'asc'; + } + + $sortClass = static function (string $key) use ($currentSort, $currentDir): string { + return $currentSort === $key + ? 'sortable sorting_' . $currentDir + : 'sortable sorting'; + }; + + $arrowState = static function (string $key) use ($currentSort, $currentDir): array { + $state = ['up' => '', 'down' => '']; + if ($currentSort === $key) { + if ($currentDir === 'asc') { + $state['up'] = 'is-active'; + } elseif ($currentDir === 'desc') { + $state['down'] = 'is-active'; + } + } + return $state; + }; + + $renderSortIcon = static function (array $state): string { + $up = $state['up'] ?? ''; + $down = $state['down'] ?? ''; + return ''; + }; + @endphp +
- - - - - - + @php $state = $arrowState('user_categoryid'); @endphp + + @php $state = $arrowState('sort_order'); @endphp + + @php $state = $arrowState('usertype_subject1'); @endphp + + @php $state = $arrowState('usertype_subject2'); @endphp + + @php $state = $arrowState('usertype_subject3'); @endphp + + @php $state = $arrowState('print_name'); @endphp + @@ -101,42 +223,28 @@ - @foreach($list as $item) + @forelse($list as $item) - - - - - - - - - + + + + + + + + - @endforeach + @empty + + + + @endforelse
- {{__('利用者分類ID')}} - - {{__('ソート順')}} - - {{__('分類名1')}} - - {{__('分類名2')}} - - {{__('分類名3')}} - - {{__('分類名')}} - + {{__('利用者分類ID')}} + {!! $renderSortIcon($state) !!} + + {{__('ソートオーダー')}} + {!! $renderSortIcon($state) !!} + + {{__('分類名1')}} + {!! $renderSortIcon($state) !!} + + {{__('分類名2')}} + {!! $renderSortIcon($state) !!} + + {{__('分類名3')}} + {!! $renderSortIcon($state) !!} + + {{__('印字名')}} + {!! $renderSortIcon($state) !!} + {{__('適用料率')}}
+ - {{ mb_substr($item->user_categoryid, 0, 10) }} - - {{ mb_substr($item->sort_order, 0, 10) }} - - {{ mb_substr($item->category_name1, 0, 10) }} - - {{ mb_substr($item->category_name2, 0, 10) }} - - {{ mb_substr($item->category_name3, 0, 10) }} - - {{ mb_substr($item->print_name, 0, 10) }} - - {{ mb_substr($item->usertype_money, 0, 10) }} - - {{ mb_substr($item->usertype_remarks, 0, 20) }} - {{ $item->user_categoryid }}{{ $item->sort_order }}{{ $item->usertype_subject1 }}{{ $item->usertype_subject2 }}{{ $item->usertype_subject3 }}{{ $item->print_name }}{{ $item->usertype_money }}{{ $item->usertype_remarks }}
{{ __('データが存在しません。') }}
@@ -148,7 +256,6 @@