Merge pull request '駐輪場空き台数計算処理修正' (#37) from main_higashide into main
All checks were successful
Deploy so-manager (auto) / deploy (push) Successful in 23s
All checks were successful
Deploy so-manager (auto) / deploy (push) Successful in 23s
Reviewed-on: #37
This commit is contained in:
commit
d2b631bbab
@ -100,13 +100,13 @@ class RegularContractCreateController extends Controller
|
||||
// zoneテーブルデータを取得(psectionテーブルとJOINしてpsection_subjectも取得)
|
||||
$zones = DB::table('zone')
|
||||
->leftJoin('psection', 'zone.psection_id', '=', 'psection.psection_id')
|
||||
->select('zone.zone_id', 'zone.park_id', 'zone.psection_id', 'zone.zone_number', 'zone.zone_tolerance', 'psection.psection_subject')
|
||||
->select('zone.zone_id', 'zone.park_id', 'zone.ptype_id', 'zone.psection_id', 'zone.zone_number', 'zone.zone_tolerance', 'psection.psection_subject')
|
||||
->get()
|
||||
->groupBy('park_id');
|
||||
|
||||
// 空き予約マスタデータを取得
|
||||
$reserve = DB::table('reserve')
|
||||
->select('reserve_id', 'park_id', 'psection_id')
|
||||
->select('reserve_id', 'park_id', 'ptype_id', 'psection_id')
|
||||
->where('valid_flag', 1)
|
||||
->get()
|
||||
->groupBy('park_id');
|
||||
|
||||
@ -89,18 +89,31 @@
|
||||
<td>
|
||||
@php
|
||||
$zonesForType = ($zones[$row->park_id] ?? collect())->where('psection_subject', $vehicle);
|
||||
@endphp
|
||||
@forelse ($zonesForType as $zone)
|
||||
@php
|
||||
// 空き台数計算
|
||||
$hasVacancy = false;
|
||||
foreach ($zonesForType as $zone) {
|
||||
$reserveCount = ($reserve[$row->park_id] ?? collect())
|
||||
->where('psection_id', $zone->psection_id)
|
||||
->where('ptype_id', $zone->ptype_id)
|
||||
->count();
|
||||
$vacancy = $zone->zone_tolerance - $zone->zone_number - $reserveCount;
|
||||
if ($vacancy > 0) {
|
||||
$hasVacancy = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 猶予期間判定
|
||||
$grace = $city_grace_periods[$row->city_id] ?? null;
|
||||
$now = \Carbon\Carbon::now();
|
||||
$gracePeriodValid =
|
||||
$grace &&
|
||||
is_numeric($grace->update_grace_period_start_date) &&
|
||||
preg_match('/^\d{1,2}:\d{2}$/', $grace->update_grace_period_start_time) &&
|
||||
is_numeric($grace->update_grace_period_end_date) &&
|
||||
preg_match('/^\d{1,2}:\d{2}$/', $grace->update_grace_period_end_time);
|
||||
|
||||
$inGrace = false;
|
||||
if ($grace && $grace->update_grace_period_start_date && $grace->update_grace_period_start_time && $grace->update_grace_period_end_date && $grace->update_grace_period_end_time) {
|
||||
if ($gracePeriodValid) {
|
||||
$now = \Carbon\Carbon::now();
|
||||
$year = $now->year;
|
||||
$month = $now->month;
|
||||
$startDay = (int)$grace->update_grace_period_start_date;
|
||||
@ -125,16 +138,17 @@
|
||||
}
|
||||
}
|
||||
@endphp
|
||||
@if ($vacancy > 0 && $inGrace)
|
||||
@if ($zonesForType->isNotEmpty() && $gracePeriodValid)
|
||||
@if ($hasVacancy && $inGrace)
|
||||
<button class="btn btn-block btn-sm btn-outline-success btn_82-table btn-popup" data-park-id="{{ $row->park_id }}">定期契約</button>
|
||||
@elseif (!$inGrace)
|
||||
<button class="btn btn-block btn-sm btn-outline-danger btn_103-table btn-popup" data-park-id="{{ $row->park_id }}">販売期間外</button>
|
||||
@elseif ($vacancy <= 0 && $inGrace)
|
||||
<button class="btn btn-block btn-sm btn-outline-danger btn_103-table btn-popup" data-park-id="{{ $row->park_id }}">空き待ち申込</button>
|
||||
@endif
|
||||
@empty
|
||||
<span class="text-muted"></span>
|
||||
@endforelse
|
||||
@elseif (!$hasVacancy && $inGrace)
|
||||
<button class="btn btn-block btn-sm btn-outline-danger btn_103-table btn-popup" data-park-id="{{ $row->park_id }}">空き待ち申込</button>
|
||||
@endif
|
||||
@else
|
||||
<span class="text-muted"></span>
|
||||
@endif
|
||||
</td>
|
||||
@endforeach
|
||||
</tr>
|
||||
|
||||
@ -36,64 +36,79 @@
|
||||
</div>
|
||||
<!-- 空き台数・契約情報 -->
|
||||
<div class="mt-3">
|
||||
@foreach($zones as $zone)
|
||||
@php
|
||||
$vacant = $vacancyData[$zone->psection_id . '_' . $zone->ptype_subject] ?? 0;
|
||||
$grace = $city_grace_periods[$park->city_id] ?? null;
|
||||
$now = \Carbon\Carbon::now();
|
||||
|
||||
// 猶予期間判定
|
||||
$isGracePeriod = false;
|
||||
if ($grace && $grace->update_grace_period_start_date && $grace->update_grace_period_start_time && $grace->update_grace_period_end_date && $grace->update_grace_period_end_time) {
|
||||
$now = \Carbon\Carbon::now();
|
||||
$year = $now->year;
|
||||
$month = $now->month;
|
||||
$startDay = (int)$grace->update_grace_period_start_date;
|
||||
$endDay = (int)$grace->update_grace_period_end_date;
|
||||
$startTime = $grace->update_grace_period_start_time;
|
||||
$endTime = $grace->update_grace_period_end_time;
|
||||
|
||||
if ($startDay > $endDay) {
|
||||
// 月またぎ
|
||||
$start = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $year, $month, $startDay, $startTime));
|
||||
$nextMonth = $month == 12 ? 1 : $month + 1;
|
||||
$nextYear = $month == 12 ? $year + 1 : $year;
|
||||
$end = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $nextYear, $nextMonth, $endDay, $endTime));
|
||||
} else {
|
||||
// 同月
|
||||
$start = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $year, $month, $startDay, $startTime));
|
||||
$end = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $year, $month, $endDay, $endTime));
|
||||
}
|
||||
$isGracePeriod = $now->between($start, $end);
|
||||
}
|
||||
$zonesByPtype = $zones->groupBy('ptype_id');
|
||||
@endphp
|
||||
<div class="mb-2">
|
||||
<strong>{{ $zone->ptype_subject }}</strong><br>
|
||||
{{ $zone->psection_subject }}:空き {{ $vacant }}台
|
||||
@if($isGracePeriod)
|
||||
@if($vacant > 0)
|
||||
<button type="button" class="btn btn-success btn-sm btn-contract"
|
||||
data-park-id="{{ $park->park_id }}"
|
||||
data-psection-id="{{ $zone->psection_id }}"
|
||||
data-ptype-id="{{ $zone->ptype_id }}">
|
||||
定期契約
|
||||
</button>
|
||||
@else
|
||||
<button type="button" class="btn btn-danger btn_103 btn-reserve"
|
||||
data-park-id="{{ $park->park_id }}"
|
||||
data-psection-id="{{ $zone->psection_id }}"
|
||||
data-ptype-id="{{ $zone->ptype_id }}">
|
||||
空き待ち申込
|
||||
</button>
|
||||
@endif
|
||||
@else
|
||||
<button type="button" class="btn btn-danger btn_103 btn-reserve"
|
||||
data-park-id="{{ $park->park_id }}"
|
||||
data-psection-id="{{ $zone->psection_id }}"
|
||||
data-ptype-id="{{ $zone->ptype_id }}">
|
||||
販売期間外
|
||||
</button>
|
||||
@endif
|
||||
@foreach($zonesByPtype as $ptypeId => $zonesGroup)
|
||||
<div class="mb-3">
|
||||
<strong>{{ $zonesGroup->first()->ptype_subject }}</strong>
|
||||
<div style="display: flex; gap: 1em;">
|
||||
@foreach($zonesGroup as $zone)
|
||||
@php
|
||||
$vacant = $vacancyData[$zone->psection_id . '_' . $zone->ptype_subject] ?? 0;
|
||||
$grace = $city_grace_periods[$park->city_id] ?? null;
|
||||
$now = \Carbon\Carbon::now();
|
||||
|
||||
// 猶予期間判定
|
||||
$isGracePeriod = false;
|
||||
if ($grace && $grace->update_grace_period_start_date && $grace->update_grace_period_start_time && $grace->update_grace_period_end_date && $grace->update_grace_period_end_time) {
|
||||
$now = \Carbon\Carbon::now();
|
||||
$year = $now->year;
|
||||
$month = $now->month;
|
||||
$startDay = (int)$grace->update_grace_period_start_date;
|
||||
$endDay = (int)$grace->update_grace_period_end_date;
|
||||
$startTime = $grace->update_grace_period_start_time;
|
||||
$endTime = $grace->update_grace_period_end_time;
|
||||
|
||||
if ($startDay > $endDay) {
|
||||
// 月またぎ
|
||||
// 前月の開始日~今月の終了日
|
||||
$prevMonth = $now->copy()->subMonth();
|
||||
$startPrev = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $prevMonth->year, $prevMonth->month, $startDay, $grace->update_grace_period_start_time));
|
||||
$endCurr = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $year, $month, $endDay, $grace->update_grace_period_end_time));
|
||||
// 今月の開始日~翌月の終了日
|
||||
$startCurr = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $year, $month, $startDay, $grace->update_grace_period_start_time));
|
||||
$nextMonth = $month == 12 ? 1 : $month + 1;
|
||||
$nextYear = $month == 12 ? $year + 1 : $year;
|
||||
$endNext = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $nextYear, $nextMonth, $endDay, $grace->update_grace_period_end_time));
|
||||
$isGracePeriod = $now->between($startPrev, $endCurr) || $now->between($startCurr, $endNext);
|
||||
} else {
|
||||
// 同月
|
||||
$start = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $year, $month, $startDay, $grace->update_grace_period_start_time));
|
||||
$end = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $year, $month, $endDay, $grace->update_grace_period_end_time));
|
||||
$isGracePeriod = $now->between($start, $end);
|
||||
}
|
||||
}
|
||||
@endphp
|
||||
<div class="mb-2">
|
||||
{{ $zone->psection_subject }}:空き {{ max(0, $vacant) }}台
|
||||
@if($isGracePeriod)
|
||||
@if($vacant > 0)
|
||||
<button type="button" class="btn btn-success btn-sm btn-contract"
|
||||
data-park-id="{{ $park->park_id }}"
|
||||
data-psection-id="{{ $zone->psection_id }}"
|
||||
data-ptype-id="{{ $zone->ptype_id }}">
|
||||
定期契約
|
||||
</button>
|
||||
@else
|
||||
<button type="button" class="btn btn-danger btn_103 btn-reserve"
|
||||
data-park-id="{{ $park->park_id }}"
|
||||
data-psection-id="{{ $zone->psection_id }}"
|
||||
data-ptype-id="{{ $zone->ptype_id }}">
|
||||
空き待ち申込
|
||||
</button>
|
||||
@endif
|
||||
@else
|
||||
<button type="button" class="btn btn-danger btn_103 btn-reserve"
|
||||
data-park-id="{{ $park->park_id }}"
|
||||
data-psection-id="{{ $zone->psection_id }}"
|
||||
data-ptype-id="{{ $zone->ptype_id }}">
|
||||
販売期間外
|
||||
</button>
|
||||
@endif
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user