【予約者一覧】【更新予定者一覧】絞り込みボダン修正
All checks were successful
Deploy main / deploy (push) Successful in 23s

This commit is contained in:
你的名字 2025-09-26 18:33:13 +09:00
parent d1ddb474d8
commit c171a26f42
4 changed files with 234 additions and 103 deletions

View File

@ -38,12 +38,18 @@ class ReservationController extends Controller
'p.park_name',
'r.price_parkplaceid',
'r.psection_id',
DB::raw('ps.psection_subject as vehicle_type'),
DB::raw('ut.usertype_subject1 as user_category1'),
DB::raw('ut.usertype_subject2 as user_category2'),
DB::raw('ut.usertype_subject3 as user_category3'),
'r.reserve_date',
'r.reserve_reduction as reduction',
'r.800m_flag as within_800m_flag',
DB::raw('r.`800m_flag` as within_800m_flag'),
])
->leftJoin('user as u', 'r.user_id', '=', 'u.user_id')
->leftJoin('park as p', 'r.park_id', '=', 'p.park_id'); // 追加
->leftJoin('park as p', 'r.park_id', '=', 'p.park_id')
->leftJoin('psection as ps','r.psection_id','=','ps.psection_id')
->leftJoin('usertype as ut','u.user_categoryid','=','ut.user_categoryid');
// フィルター条件
if ($request->filled('park_id')) {
@ -52,8 +58,13 @@ class ReservationController extends Controller
if ($request->filled('user_id')) {
$q->where('r.user_id', $request->input('user_id'));
}
if ($request->filled('user_categoryid')) {
$q->where('r.user_categoryid', $request->input('user_categoryid'));
// 利用者分類契約者一覧に合わせ、分類名1の完全一致を優先
if ($request->filled('user_category1')) {
$val = trim(mb_convert_kana($request->input('user_category1'), 'asKV'));
$q->where('ut.usertype_subject1', $val);
} elseif ($request->filled('user_categoryid')) {
// 既存互換ID指定も残す
$q->where('u.user_categoryid', $request->input('user_categoryid'));
}
if ($request->filled('user_tag_serial')) {
$q->where('u.user_tag_serial', 'like', '%' . $request->input('user_tag_serial') . '%');
@ -71,7 +82,11 @@ class ReservationController extends Controller
});
}
if ($request->filled('user_primemail')) {
$q->where('u.user_primemail', 'like', '%' . $request->input('user_primemail') . '%');
$like = '%' . $request->input('user_primemail') . '%';
$q->where(function($w) use ($like){
$w->where('u.user_primemail','like',$like)
->orWhere('u.user_submail','like',$like);
});
}
if ($request->filled('user_workplace')) {
$q->where('u.user_workplace', 'like', '%' . $request->input('user_workplace') . '%');
@ -80,19 +95,26 @@ class ReservationController extends Controller
$q->where('u.user_school', 'like', '%' . $request->input('user_school') . '%');
}
// ソート
$sort = $request->input('sort', 'r.reserve_id');
$sortType = $request->input('sort_type', 'desc');
$allowSorts = ['r.reserve_id', 'r.reserve_date', 'r.reserve_start', 'r.reserve_end'];
if (!in_array($sort, $allowSorts)) {
$sort = 'r.reserve_id';
}
$sortType = ($sortType === 'asc') ? 'asc' : 'desc';
// ソート(契約者一覧に合わせて許可する列を拡張)
$sort = $request->input('sort', 'reserve_id');
$sortType = $request->input('sort_type', 'asc');
$allow = [
'reserve_id' => 'r.reserve_id',
'user_id' => 'r.user_id',
'user_name' => 'u.user_name',
'park_id' => 'r.park_id',
'price_parkplaceid' => 'r.price_parkplaceid',
'psection_id' => 'r.psection_id',
'reserve_date' => 'r.reserve_date',
];
if (!isset($allow[$sort])) $sort = 'reserve_id';
$sortType = $sortType === 'desc' ? 'desc' : 'asc';
$rows = $q->orderBy($sort, $sortType)->paginate(20)->withQueryString();
$rows = $q->orderBy($allow[$sort], $sortType)
->paginate(20)->withQueryString();
// 駐輪場リスト取得(必要なら)
$parks = DB::table('park')->select('park_id', 'park_name')->get();
$parks = DB::table('park')->select('park_id', 'park_name')->orderBy('park_name')->get();
return view('admin.reservation.list', compact('rows', 'sort', 'sortType', 'parks'));
}

View File

@ -14,32 +14,26 @@ class UpdateCandidateController extends Controller
public function list(Request $request)
{
$q = DB::table('regular_contract as rc')
->leftJoin('user as u','rc.user_id','=','u.user_id')
->leftJoin('park as p','rc.park_id','=','p.park_id')
->leftJoin('psection as ps','rc.psection_id','=','ps.psection_id')
->leftJoin('usertype as ut','u.user_categoryid','=','ut.user_categoryid')
->select([
'rc.contract_id',
'rc.contract_qr_id',
'rc.user_id',
'rc.user_categoryid',
'rc.park_id',
'rc.contract_created_at',
'rc.contract_periods',
'rc.contract_periode',
'rc.tag_qr_flag',
'rc.contract_flag',
'rc.contract_cancel_flag',
'rc.contract_payment_day',
'rc.contract_money',
'rc.billing_amount',
'rc.contract_permission',
'rc.contract_manual',
'rc.contract_notice',
'p.park_name',
'u.user_name',
'u.user_phonetic',
'u.user_mobile',
'u.user_homephone',
'u.user_primemail',
'u.user_gender',
'u.user_birthdate',
'u.user_gender',
'u.user_regident_zip',
'u.user_regident_pre',
'u.user_regident_city',
@ -48,57 +42,116 @@ class UpdateCandidateController extends Controller
'u.user_relate_pre',
'u.user_relate_city',
'u.user_relate_add',
'u.user_graduate',
'u.user_workplace',
'u.user_school',
'u.user_graduate',
'u.user_reduction',
'u.user_remarks',
'p.park_name',
DB::raw('ps.psection_subject as vehicle_type'),
DB::raw('ut.usertype_subject1 as user_category1'),
DB::raw('ut.usertype_subject2 as user_category2'),
DB::raw('ut.usertype_subject3 as user_category3'),
DB::raw('rc.contract_seal_issue as seal_issue_count'),
DB::raw('rc.user_securitynum as crime_prevention'),
DB::raw("CASE rc.enable_months
WHEN 1 THEN '月極(1ヶ月)'
WHEN 3 THEN '3ヶ月'
WHEN 6 THEN '6ヶ月'
WHEN 12 THEN '年'
ELSE CONCAT(rc.enable_months,'ヶ月') END as ticket_type"),
])
->leftJoin('park as p', 'rc.park_id', '=', 'p.park_id')
->leftJoin('user as u', 'rc.user_id', '=', 'u.user_id')
->whereNull('rc.update_flag'); // 未更新のみ
->where('rc.contract_cancel_flag',0)
->where('rc.contract_permission',1)
// 追加: 本日以降が有効期限のレコードのみ
->whereDate('rc.contract_periode','>=', now()->toDateString());
// 対象月による有効期限の絞り込み
if ($request->filled('target_month')) {
$now = now();
switch ($request->input('target_month')) {
case 'last':
$start = $now->copy()->subMonth()->startOfMonth();
$end = $now->copy()->subMonth()->endOfMonth();
break;
case 'this':
$start = $now->copy()->startOfMonth();
$end = $now->copy()->endOfMonth();
break;
case 'next':
$start = $now->copy()->addMonth()->startOfMonth();
$end = $now->copy()->addMonth()->endOfMonth();
break;
case 'after2':
$start = $now->copy()->addMonths(2)->startOfMonth();
$end = $now->copy()->addMonths(2)->endOfMonth();
break;
default:
$start = null;
$end = null;
// 絞り込み
if ($request->filled('park_id')) {
$q->where('rc.park_id', $request->park_id);
}
if ($start && $end) {
$q->whereBetween('rc.contract_periode', [$start->toDateString(), $end->toDateString()]);
if ($request->filled('user_id')) {
$q->where('rc.user_id', trim($request->user_id));
}
// 分類名1 完全一致
if ($request->filled('user_category1')) {
$val = trim(mb_convert_kana($request->user_category1,'asKV'));
$q->where('ut.usertype_subject1', $val);
}
// タグシリアル64進 部分一致 (SELECT 不要)
if ($request->filled('user_tag_serial_64')) {
$q->where('u.user_tag_serial_64','like','%'.$request->user_tag_serial_64.'%');
}
// 有効期限:指定日以前
if ($request->filled('contract_periode')) {
$raw = str_replace('/','-',$request->contract_periode);
try {
$target = \Carbon\Carbon::parse($raw)->format('Y-m-d');
$q->whereDate('rc.contract_periode','<=',$target);
} catch (\Exception $e) {}
}
if ($request->filled('user_phonetic')) {
$q->where('u.user_phonetic','like','%'.$request->user_phonetic.'%');
}
if ($request->filled('user_mobile')) {
$like = '%'.$request->user_mobile.'%';
$q->where(function($w) use ($like){
$w->where('u.user_mobile','like',$like)
->orWhere('u.user_homephone','like',$like);
});
}
if ($request->filled('user_primemail')) {
$like = '%'.$request->user_primemail.'%';
$q->where(function($w) use ($like){
$w->where('u.user_primemail','like',$like)
->orWhere('u.user_submail','like',$like);
});
}
if ($request->filled('user_workplace')) {
$q->where('u.user_workplace','like','%'.$request->user_workplace.'%');
}
if ($request->filled('user_school')) {
$q->where('u.user_school','like','%'.$request->user_school.'%');
}
if ($request->filled('tag_qr_flag') && $request->tag_qr_flag!=='') {
$q->where('rc.tag_qr_flag',$request->tag_qr_flag);
}
// 対象月
$target = $request->input('target_month');
if (in_array($target,['last','this','next','after2'],true)) {
$base = now()->startOfMonth();
$offset = ['last'=>-1,'this'=>0,'next'=>1,'after2'=>2][$target];
$m = $base->copy()->addMonths($offset);
if ($target === 'after2') {
// 2か月後「以降」を抽出該当月の月初以降
$q->whereDate('rc.contract_periode', '>=', $m->toDateString());
} else {
$q->whereYear('rc.contract_periode',$m->year)
->whereMonth('rc.contract_periode',$m->month);
}
}
$sort = $request->input('sort', 'rc.contract_id');
$sortType = $request->input('sort_type', 'desc');
$allowSorts = ['rc.contract_id'];
if (!in_array($sort, $allowSorts)) {
$sort = 'rc.contract_id';
}
$sortType = ($sortType === 'asc') ? 'asc' : 'desc';
// ソートregular_contract の表示順に合わせて contract_id の降順を既定に)
$sort = $request->input('sort','contract_id');
$sortType = $request->input('sort_type','dac');
$allow = [
'contract_id' => 'rc.contract_id',
'user_id' => 'rc.user_id',
'contract_periode' => 'rc.contract_periode',
];
if (!isset($allow[$sort])) $sort = 'contract_id';
$sortType = $sortType==='desc' ? 'desc' : 'asc';
$q->orderBy($allow[$sort], $sortType);
$rows = $q->orderBy($sort, $sortType)->paginate(20)->withQueryString();
$rows = $q->paginate(20)->appends($request->query());
// 駐輪場リスト(プルダウン用)
$parks = DB::table('park')->select('park_id', 'park_name')->orderBy('park_name')->get();
$parks = DB::table('park')
->select('park_id','park_name')
->orderBy('park_name')
->get();
return view('admin.update_candidate.list', compact('rows', 'sort', 'sortType', 'parks'));
return view('admin.update_candidate.list',
compact('rows','parks'));
}
}

View File

@ -42,7 +42,7 @@
@endforeach
</select>
@else
<input type="text" name="park_name" value="{{ request('park_name') }}" class="form-control" placeholder="全て">
<input type="text" name="park_name" value="{{ request('park_name') }}" class="form-control" >
@endisset
</div>
</div>
@ -50,28 +50,32 @@
<div class="form-group row">
<label class="col-sm-3 col-form-label">利用者ID</label>
<div class="col-sm-9">
<input type="text" name="user_id" value="{{ request('user_id') }}" class="form-control" placeholder="123456">
<input type="text" name="user_id" value="{{ request('user_id') }}" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">利用者分類</label>
<div class="col-sm-9">
<input type="text" name="user_categoryid" value="{{ request('user_categoryid') }}" class="form-control" placeholder="全て">
<input type="text" name="user_category1" value="{{ request('user_category1') }}" class="form-control" placeholder="分類名1">
{{-- 既存互換: IDパラメータが残る可能性があるため hidden で保持 --}}
@if(request()->filled('user_categoryid'))
<input type="hidden" name="user_categoryid" value="{{ request('user_categoryid') }}">
@endif
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">タグシリアル</label>
<div class="col-sm-9">
<input type="text" name="user_tag_serial" value="{{ request('user_tag_serial') }}" class="form-control" placeholder="キーワード…">
<input type="text" name="user_tag_serial" value="{{ request('user_tag_serial') }}" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">タグシリアル64進</label>
<div class="col-sm-9">
<input type="text" name="user_tag_serial_64" value="{{ request('user_tag_serial_64') }}" class="form-control" placeholder="キーワード…">
<input type="text" name="user_tag_serial_64" value="{{ request('user_tag_serial_64') }}" class="form-control" >
</div>
</div>
</div>
@ -81,35 +85,35 @@
<div class="form-group row">
<label class="col-sm-3 col-form-label">フリガナ</label>
<div class="col-sm-9">
<input type="text" name="user_phonetic" value="{{ request('user_phonetic') }}" class="form-control" placeholder="123456">
<input type="text" name="user_phonetic" value="{{ request('user_phonetic') }}" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">電話番号</label>
<div class="col-sm-9">
<input type="text" name="user_mobile" value="{{ request('user_mobile') }}" class="form-control" placeholder="123456">
<input type="text" name="user_mobile" value="{{ request('user_mobile') }}" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">メールアドレス</label>
<div class="col-sm-9">
<input type="text" name="user_primemail" value="{{ request('user_primemail') }}" class="form-control" placeholder="キーワード…">
<input type="text" name="user_primemail" value="{{ request('user_primemail') }}" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">勤務先</label>
<div class="col-sm-9">
<input type="text" name="user_workplace" value="{{ request('user_workplace') }}" class="form-control" placeholder="キーワード…">
<input type="text" name="user_workplace" value="{{ request('user_workplace') }}" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">学校</label>
<div class="col-sm-9">
<input type="text" name="user_school" value="{{ request('user_school') }}" class="form-control" placeholder="キーワード…">
<input type="text" name="user_school" value="{{ request('user_school') }}" class="form-control" >
</div>
</div>
</div>
@ -122,13 +126,36 @@
</div>
</form>
{{-- 一覧テーブル(そのまま --}}
{{-- 一覧テーブル(ソート機能付きヘッダー --}}
<div class="table-responsive">
<table class="table table-bordered table-hover table-sm rv-table text-nowrap">
<thead>
<tr>
<th>利用者ID</th>
<th>氏名</th>
{{-- ソート可能な項目にはリンクを追加 --}}
<th>
<a href="{{ request()->fullUrlWithQuery(['sort' => 'user_id', 'sort_type' => request('sort') === 'user_id' && request('sort_type') === 'desc' ? 'asc' : 'desc']) }}" class="text-dark text-decoration-none">
利用者ID
@if(request('sort') === 'user_id' && request('sort_type') === 'asc')
<span class="text-muted"></span>
@elseif(request('sort') === 'user_id' && request('sort_type') === 'desc')
<span class="text-muted"></span>
@else
<span class="text-muted">↑↓</span>
@endif
</a>
</th>
<th>
<a href="{{ request()->fullUrlWithQuery(['sort' => 'user_name', 'sort_type' => request('sort') === 'user_name' && request('sort_type') === 'desc' ? 'asc' : 'desc']) }}" class="text-dark text-decoration-none">
氏名
@if(request('sort') === 'user_name' && request('sort_type') === 'asc')
<span class="text-muted"></span>
@elseif(request('sort') === 'user_name' && request('sort_type') === 'desc')
<span class="text-muted"></span>
@else
<span class="text-muted">↑↓</span>
@endif
</a>
</th>
<th>フリガナ</th>
<th>居住所:郵便番号</th>
<th>居住所:都道府県</th>
@ -149,13 +176,45 @@
<th>利用者分類1</th>
<th>利用者分類2</th>
<th>利用者分類3</th>
<th>駐輪場ID</th>
<th>駐輪場名</th> <!-- 追加 -->
<th>駐輪場所ID</th>
<th>車種区分ID</th>
<th>
<a href="{{ request()->fullUrlWithQuery(['sort' => 'park_id', 'sort_type' => request('sort') === 'park_id' && request('sort_type') === 'desc' ? 'asc' : 'desc']) }}" class="text-dark text-decoration-none">
駐輪場ID
@if(request('sort') === 'park_id' && request('sort_type') === 'asc')
<span class="text-muted"></span>
@elseif(request('sort') === 'park_id' && request('sort_type') === 'desc')
<span class="text-muted"></span>
@else
<span class="text-muted">↑↓</span>
@endif
</a>
</th>
<th>
<a href="{{ request()->fullUrlWithQuery(['sort' => 'price_parkplaceid', 'sort_type' => request('sort') === 'price_parkplaceid' && request('sort_type') === 'desc' ? 'asc' : 'desc']) }}" class="text-dark text-decoration-none">
駐輪場所ID
@if(request('sort') === 'price_parkplaceid' && request('sort_type') === 'asc')
<span class="text-muted"></span>
@elseif(request('sort') === 'price_parkplaceid' && request('sort_type') === 'desc')
<span class="text-muted"></span>
@else
<span class="text-muted">↑↓</span>
@endif
</a>
</th>
<th>
<a href="{{ request()->fullUrlWithQuery(['sort' => 'psection_id', 'sort_type' => request('sort') === 'psection_id' && request('sort_type') === 'desc' ? 'asc' : 'desc']) }}" class="text-dark text-decoration-none">
車種区分ID
@if(request('sort') === 'psection_id' && request('sort_type') === 'asc')
<span class="text-muted"></span>
@elseif(request('sort') === 'psection_id' && request('sort_type') === 'desc')
<span class="text-muted"></span>
@else
<span class="text-muted">↑↓</span>
@endif
</a>
</th>
<th>予約日時</th>
<th>減免措置</th>
<th>800M以内フラグ</th>
<th>M以内フラグ</th>
</tr>
</thead>
<tbody>
@ -179,20 +238,22 @@
<td>{{ $row->user_school }}</td>
<td>{{ $row->user_graduate }}</td>
<td>{{ $row->user_remarks }}</td>
<td>{{ data_get($row,'reserve_id', data_get($row,'contract_id','')) }}</td>
<td>{{ $row->reserve_id }}</td>
<td>{{ $row->user_category1 ?? '' }}</td>
<td>{{ $row->user_category2 ?? '' }}</td>
<td>{{ $row->user_category3 ?? '' }}</td>
<td>{{ $row->park_id }}</td>
<td>{{ $row->park_name }}</td>
<td>{{ $row->price_parkplaceid }}</td>
<td>{{ $row->psection_id }}</td>
<td>{{ $row->reserve_date }}</td>
<td>{{ data_get($row,'reduction', data_get($row,'reserve_reduction','')) }}</td>
<td>{{ $row->reduction ?? '' }}</td>
<td>
@php $f800 = data_get($row,'within_800m_flag', data_get($row,'flag_800m', null)); @endphp
{{ (string)$f800 === '1' ? '以内' : '' }}
{{ (string)$f800 === '1' ? 'M以内' : '' }}
</td>
</tr>
@empty
<tr><td colspan="29" class="text-center">データがありません。</td></tr>
<tr><td colspan="28" class="text-center">データがありません。</td></tr>
@endforelse
</tbody>
</table>

View File

@ -57,7 +57,7 @@
<div class="form-group row">
<label class="col-sm-3 col-form-label">利用者分類</label>
<div class="col-sm-9">
<input type="text" name="user_categoryid" value="{{ request('user_categoryid') }}" class="form-control">
<input type="text" name="user_category1" value="{{ request('user_category1') }}" class="form-control" placeholder="分類名1">
</div>
</div>
@ -79,8 +79,13 @@
<label class="col-sm-3 col-form-label">対象月</label>
<div class="col-sm-9 d-flex align-items-center">
@php
$target_month = request('target_month', 'this');
// 既定選択なし(送信時だけ適用)
$target_month = request('target_month');
@endphp
<div class="form-check mr-3">
<input class="form-check-input" type="radio" name="target_month" id="none_month" value="" {{ $target_month === null || $target_month === '' ? 'checked' : '' }}>
<label class="form-check-label" for="none_month">指定なし</label>
</div>
<div class="form-check mr-3">
<input class="form-check-input" type="radio" name="target_month" id="last_month" value="last" {{ $target_month === 'last' ? 'checked' : '' }}>
<label class="form-check-label" for="last_month">先月</label>
@ -166,17 +171,7 @@
<th>利用者ID</th>
<th>氏名</th>
<th>フリガナ</th>
<th>
<a href="{{ request()->fullUrlWithQuery([
'sort' => 'contract_id',
'sort_type' => (request('sort') === 'contract_id' && request('sort_type') === 'asc') ? 'desc' : 'asc'
]) }}">
定期契約ID
@if(request('sort') === 'contract_id')
@if(request('sort_type') === 'asc') @else @endif
@endif
</a>
</th>
<th>定期契約ID</th>
<th>タグ・QR</th>
<th>駐輪場</th>
<th>車種区分</th>