【有効期限】から【対象月】へ変更
All checks were successful
Deploy main / deploy (push) Successful in 23s

This commit is contained in:
你的名字 2025-10-15 18:56:29 +09:00
parent f9b01bde8b
commit 3518a63397
2 changed files with 39 additions and 15 deletions

View File

@ -101,16 +101,18 @@ class ContractorListController extends Controller
$q->where('u.user_tag_serial_64','like','%'.$val.'%');
}
// 有効期限で絞る(指定日以前を抽出する= <= を使用)
if ($request->filled('contract_periode')) {
$raw = trim($request->contract_periode);
$norm = str_replace('/', '-', $raw); // スラッシュ入力を許容
try {
$target = \Carbon\Carbon::parse($norm)->format('Y-m-d');
// 指定日「以前」を含める
$q->whereDate('rc.contract_periode', '<=', $target);
} catch (\Exception $e) {
// 無効な日付は無視する
// 対象月
$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);
}
}

View File

@ -94,14 +94,36 @@
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">有効期限</label>
<div class="col-sm-9">
<input type="date" name="contract_periode" value="{{ request('contract_periode') }}"
class="form-control">
<div class="form-group row">
<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');
@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>
</div>
<div class="form-check mr-3">
<input class="form-check-input" type="radio" name="target_month" id="this_month" value="this" {{ $target_month === 'this' ? 'checked' : '' }}>
<label class="form-check-label" for="this_month">今月</label>
</div>
<div class="form-check mr-3">
<input class="form-check-input" type="radio" name="target_month" id="next_month" value="next" {{ $target_month === 'next' ? 'checked' : '' }}>
<label class="form-check-label" for="next_month">来月</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="target_month" id="after_2_month" value="after2" {{ $target_month === 'after2' ? 'checked' : '' }}>
<label class="form-check-label" for="after_2_month">2か月後</label>
</div>
</div>
</div>
</div>
{{-- 右カラム --}}
<div class="col-md-6">