@extends('layouts.app')
@section('content')
@if($isRegularContract)
新規定期契約 > 空き駐輪場を確認する
@else
駐輪場検索 > 駐輪場選択
@endif
@forelse($parks_table as $row)
|
{{ $row->city_name }} |
{{ $row->station_neighbor_station }} |
{{-- 自転車・原付・自動二輪・自動車列 --}}
@foreach(['自転車', '原付', '自動二輪', '自動車'] as $vehicle)
@php
$zonesForType = ($zones[$row->park_id] ?? collect())->where('psection_subject', $vehicle);
// 空き台数計算
$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;
$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 ($gracePeriodValid) {
$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;
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));
$inGrace = $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));
$inGrace = $now->between($start, $end);
}
}
@endphp
@if ($zonesForType->isNotEmpty() && $gracePeriodValid)
@if ($hasVacancy && $inGrace)
@elseif (!$inGrace)
@elseif (!$hasVacancy && $inGrace)
@endif
@else
@endif
|
@endforeach
@empty
| 該当する駐輪場はありません。 |
@endforelse
@php
$totalPages = ceil($parks_table_total / $parks_table_perPage);
$currentPage = $parks_table_page;
@endphp
@endsection