【シール発行履歴】プルダウン内容修正
This commit is contained in:
parent
d1277a2b4a
commit
c43a16ed79
@ -10,66 +10,69 @@ class SealsController extends Controller
|
|||||||
{
|
{
|
||||||
public function list(Request $request)
|
public function list(Request $request)
|
||||||
{
|
{
|
||||||
// ソート用パラメータ取得(指定がなければnull)
|
$q = \DB::table('seal as s')
|
||||||
$sort = $request->input('sort');
|
->leftJoin('park as p','s.park_id','=','p.park_id')
|
||||||
$sort_type = $request->input('sort_type', 'asc');
|
->leftJoin('regular_contract as rc','s.contract_id','=','rc.contract_id')
|
||||||
|
->leftJoin('psection as ps','rc.psection_id','=','ps.psection_id')
|
||||||
|
->select([
|
||||||
|
's.seal_issueid',
|
||||||
|
's.park_id',
|
||||||
|
'p.park_name',
|
||||||
|
's.contract_id',
|
||||||
|
'rc.psection_id',
|
||||||
|
\DB::raw('ps.psection_subject AS psection_subject'),
|
||||||
|
'rc.contract_seal_issue',
|
||||||
|
's.seal_day',
|
||||||
|
's.seal_reason',
|
||||||
|
]);
|
||||||
|
|
||||||
// sealテーブルを参照し、フィルター
|
// 駐輪場フィルタ
|
||||||
$query = DB::table('seal');
|
if($request->filled('park_id')){
|
||||||
|
$q->where('s.park_id',$request->park_id);
|
||||||
// フィルター:発行日
|
|
||||||
$periodType = $request->input('period_type');
|
|
||||||
$recentPeriod = $request->input('recent_period');
|
|
||||||
$sealDayFrom = $request->input('seal_day_from');
|
|
||||||
$sealDayTo = $request->input('seal_day_to');
|
|
||||||
|
|
||||||
if ($periodType === 'range' && $sealDayFrom && $sealDayTo) {
|
|
||||||
$query->whereBetween('seal_day', [$sealDayFrom, $sealDayTo]);
|
|
||||||
} elseif ($periodType === 'recent' && $recentPeriod) {
|
|
||||||
$now = date('Y-m-d');
|
|
||||||
switch ($recentPeriod) {
|
|
||||||
case '12m':
|
|
||||||
$from = date('Y-m-d', strtotime('-12 months', strtotime($now)));
|
|
||||||
break;
|
|
||||||
case '6m':
|
|
||||||
$from = date('Y-m-d', strtotime('-6 months', strtotime($now)));
|
|
||||||
break;
|
|
||||||
case '3m':
|
|
||||||
$from = date('Y-m-d', strtotime('-3 months', strtotime($now)));
|
|
||||||
break;
|
|
||||||
case '2m':
|
|
||||||
$from = date('Y-m-d', strtotime('-2 months', strtotime($now)));
|
|
||||||
break;
|
|
||||||
case '1m':
|
|
||||||
$from = date('Y-m-d', strtotime('-1 months', strtotime($now)));
|
|
||||||
break;
|
|
||||||
case '1w':
|
|
||||||
$from = date('Y-m-d', strtotime('-1 week', strtotime($now)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$from = null;
|
|
||||||
}
|
|
||||||
if (isset($from)) {
|
|
||||||
$query->where('seal_day', '>=', $from);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// デフォルト:直近3ヶ月
|
|
||||||
$now = date('Y-m-d');
|
|
||||||
$from = date('Y-m-d', strtotime('-3 months', strtotime($now)));
|
|
||||||
$query->where('seal_day', '>=', $from);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ソート指定があればorderBy、なければDB物理順
|
// 期間フィルタ
|
||||||
if ($sort) {
|
$periodType = $request->input('period_type','range');
|
||||||
$list = $query->orderBy($sort, $sort_type)->paginate(20);
|
if($periodType === 'range'){
|
||||||
} else {
|
if($request->filled('seal_day_from')){
|
||||||
$list = $query->paginate(20);
|
$q->whereDate('s.seal_day','>=',$request->seal_day_from);
|
||||||
|
}
|
||||||
|
if($request->filled('seal_day_to')){
|
||||||
|
$q->whereDate('s.seal_day','<=',$request->seal_day_to);
|
||||||
|
}
|
||||||
|
} elseif($periodType === 'recent' && $request->filled('recent_period')){
|
||||||
|
$map = ['12m'=>12,'6m'=>6,'3m'=>3,'2m'=>2,'1m'=>1,'1w'=>'1w'];
|
||||||
|
$key = $request->recent_period;
|
||||||
|
if(isset($map[$key])){
|
||||||
|
$from = $key==='1w' ? now()->subWeek() : now()->subMonths($map[$key]);
|
||||||
|
$q->where('s.seal_day','>=',$from->toDateString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin.seals.list', [
|
// --- 並び替え: パラメータがある場合のみ適用 ---
|
||||||
'list' => $list,
|
$sort = $request->query('sort'); // デフォルト null
|
||||||
'sort' => $sort,
|
$sortType = $request->query('sort_type','asc'); // 指定なければ asc
|
||||||
'sort_type' => $sort_type,
|
$allow = [
|
||||||
]);
|
'seal_issueid' => 's.seal_issueid',
|
||||||
|
'park_id' => 'p.park_name',
|
||||||
|
'contract_id' => 's.contract_id',
|
||||||
|
'seal_day' => 's.seal_day',
|
||||||
|
'contract_seal_issue' => 'rc.contract_seal_issue',
|
||||||
|
'psection_subject' => 'ps.psection_subject',
|
||||||
|
];
|
||||||
|
if(isset($allow[$sort])){
|
||||||
|
$sortType = $sortType === 'desc' ? 'desc' : 'asc';
|
||||||
|
$q->orderBy($allow[$sort], $sortType);
|
||||||
|
}
|
||||||
|
// 並び替え指定が無い時は orderBy 不要 → DB の物理(主キー)順
|
||||||
|
|
||||||
|
$list = $q->paginate(20)->appends($request->query());
|
||||||
|
|
||||||
|
$parks = \DB::table('park')
|
||||||
|
->select('park_id','park_name')
|
||||||
|
->orderBy('park_name')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return view('admin.seals.list', compact('list','parks','sort','sortType'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -22,46 +22,50 @@
|
|||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<select name="park_id" class="form-select">
|
<select name="park_id" class="form-select">
|
||||||
<option value="">全て</option>
|
<option value="">全て</option>
|
||||||
{{-- @foreach($parks as $park)
|
@foreach($parks as $park)
|
||||||
<option value="{{ $park->id }}" {{ request('park_id') == $park->id ? 'selected' : '' }}>{{ $park->name }}</option>
|
<option value="{{ $park->park_id }}"
|
||||||
@endforeach --}}
|
|
||||||
|
{{ (string)request('park_id') === (string)$park->park_id ? 'selected' : '' }}>
|
||||||
|
{{ $park->park_name }}
|
||||||
|
</option>
|
||||||
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-3 align-items-center">
|
<div class="row mb-3 align-items-center">
|
||||||
<label class="col-sm-2 col-form-label fw-bold py-0">発行日</label>
|
<label class="col-sm-2 col-form-label fw-bold py-0">発行日</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<div class="row g-2 align-items-center mb-0">
|
<div class="row align-items-center mb-0">
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline me-2">
|
||||||
<input class="form-check-input" type="radio" name="period_type" id="period_type_range" value="range" {{ request('period_type', 'range') == 'range' ? 'checked' : '' }}>
|
<input class="form-check-input" type="radio" name="period_type" id="period_type_range" value="range" {{ request('period_type', 'range') == 'range' ? 'checked' : '' }}>
|
||||||
<label class="form-check-label" for="period_type_range">範囲指定</label>
|
<label class="form-check-label" for="period_type_range">範囲指定</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-auto">
|
<div class="col-auto ms-3">
|
||||||
<div class="input-group">
|
<div class="d-flex align-items-center">
|
||||||
<input type="date" name="seal_day_from" id="seal_day_from" class="form-control" value="{{ request('seal_day_from') }}">
|
<input type="date" name="seal_day_from" id="seal_day_from" class="form-control" style="width:160px;" value="{{ request('seal_day_from') }}">
|
||||||
<span class="input-group-text">~</span>
|
<span class="mx-3 fw-bold">~</span>
|
||||||
<input type="date" name="seal_day_to" id="seal_day_to" class="form-control" value="{{ request('seal_day_to') }}">
|
<input type="date" name="seal_day_to" id="seal_day_to" class="form-control" style="width:160px;" value="{{ request('seal_day_to') }}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row g-2 align-items-center">
|
<div class="row align-items-center mt-2">
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline me-2">
|
||||||
<input class="form-check-input" type="radio" name="period_type" id="period_type_recent" value="recent" {{ request('period_type') == 'recent' ? 'checked' : '' }}>
|
<input class="form-check-input" type="radio" name="period_type" id="period_type_recent" value="recent" {{ request('period_type') == 'recent' ? 'checked' : '' }}>
|
||||||
<label class="form-check-label" for="period_type_recent">直近Nヶ月等</label>
|
<label class="form-check-label" for="period_type_recent">直近Nヶ月等</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-auto">
|
<div class="col-auto ms-3">
|
||||||
<select name="recent_period" id="recent_period" class="form-select">
|
<select name="recent_period" id="recent_period" class="form-select">
|
||||||
<option value="">全て</option>
|
<option value="">全て</option>
|
||||||
<option value="12m" {{ request('recent_period') == '12m' ? 'selected' : '' }}>直近12ヶ月</option>
|
<option value="12m" {{ request('recent_period') == '12m' ? 'selected' : '' }}>直近12ヶ月</option>
|
||||||
<option value="6m" {{ request('recent_period') == '6m' ? 'selected' : '' }}>直近6ヶ月</option>
|
<option value="6m" {{ request('recent_period') == '6m' ? 'selected' : '' }}>直近6ヶ月</option>
|
||||||
<option value="3m" {{ request('recent_period') == '3m' ? 'selected' : '' }}>直近3ヶ月</option>
|
<option value="3m" {{ request('recent_period') == '3m' ? 'selected' : '' }}>直近3ヶ月</option>
|
||||||
<option value="2m" {{ request('recent_period') == '2m' ? 'selected' : '' }}>直近2ヶ月</option>
|
<option value="2m" {{ request('recent_period') == '2m' ? 'selected' : '' }}>直近2ヶ月</option>
|
||||||
<option value="1m" {{ request('recent_period') == '1m' ? 'selected' : '' }}>直近1ヶ月</option>
|
<option value="1m" {{ request('recent_period') == '1m' ? 'selected' : '' }}>直近1ヶ月</option>
|
||||||
<option value="1w" {{ request('recent_period') == '1w' ? 'selected' : '' }}>直近1週間</option>
|
<option value="1w" {{ request('recent_period') == '1w' ? 'selected' : '' }}>直近1週間</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -90,20 +94,20 @@
|
|||||||
<table class="table table-bordered table-hover table-sm dataTable">
|
<table class="table table-bordered table-hover table-sm dataTable">
|
||||||
<thead class="thead-light">
|
<thead class="thead-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="sorting {{ ($sort=='seal_issueid') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="seal_issueid" style="cursor:pointer;">
|
<th class="sorting {{ ($sort=='seal_issueid') ? ($sortType=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="seal_issueid" style="cursor:pointer;">
|
||||||
シール発行履歴ID
|
シール発行履歴ID
|
||||||
</th>
|
</th>
|
||||||
<th class="sorting {{ ($sort=='park_id') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="park_id" style="cursor:pointer;">
|
<th class="sorting {{ ($sort=='park_id') ? ($sortType=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="park_id" style="cursor:pointer;">
|
||||||
シール発行駐輪場
|
シール発行駐輪場
|
||||||
</th>
|
</th>
|
||||||
<th class="sorting {{ ($sort=='contract_id') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="contract_id" style="cursor:pointer;">
|
<th class="sorting {{ ($sort=='contract_id') ? ($sortType=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="contract_id" style="cursor:pointer;">
|
||||||
定期契約ID
|
定期契約ID
|
||||||
</th>
|
</th>
|
||||||
<th>車種区分ID</th>
|
<th>車種区分ID</th>
|
||||||
<th class="sorting {{ ($sort=='seal_day') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="seal_day" style="cursor:pointer;">
|
<th class="sorting {{ ($sort=='seal_day') ? ($sortType=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="seal_day" style="cursor:pointer;">
|
||||||
発行日
|
発行日
|
||||||
</th>
|
</th>
|
||||||
<th class="sorting {{ ($sort=='contract_seal_issue') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="contract_seal_issue" style="cursor:pointer;">
|
<th class="sorting {{ ($sort=='contract_seal_issue') ? ($sortType=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="contract_seal_issue" style="cursor:pointer;">
|
||||||
発行回数
|
発行回数
|
||||||
</th>
|
</th>
|
||||||
<th>理由</th>
|
<th>理由</th>
|
||||||
@ -115,7 +119,7 @@
|
|||||||
<td>{{ $item->seal_issueid }}</td>
|
<td>{{ $item->seal_issueid }}</td>
|
||||||
<td>{{ $item->park_name ?? $item->park_id }}</td>
|
<td>{{ $item->park_name ?? $item->park_id }}</td>
|
||||||
<td>{{ $item->contract_id }}</td>
|
<td>{{ $item->contract_id }}</td>
|
||||||
<td>{{ $item->psection_name ?? $item->psection_id }}</td>
|
<td>{{ $item->psection_subject ?? $item->psection_id }}</td>
|
||||||
<td>{{ $item->seal_day }}</td>
|
<td>{{ $item->seal_day }}</td>
|
||||||
<td>{{ $item->contract_seal_issue }}</td>
|
<td>{{ $item->contract_seal_issue }}</td>
|
||||||
<td>{{ $item->seal_reason }}</td>
|
<td>{{ $item->seal_reason }}</td>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user