駐輪場空き台数計算処理修正 #37
@ -100,13 +100,13 @@ class RegularContractCreateController extends Controller
|
|||||||
// zoneテーブルデータを取得(psectionテーブルとJOINしてpsection_subjectも取得)
|
// zoneテーブルデータを取得(psectionテーブルとJOINしてpsection_subjectも取得)
|
||||||
$zones = DB::table('zone')
|
$zones = DB::table('zone')
|
||||||
->leftJoin('psection', 'zone.psection_id', '=', 'psection.psection_id')
|
->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()
|
->get()
|
||||||
->groupBy('park_id');
|
->groupBy('park_id');
|
||||||
|
|
||||||
// 空き予約マスタデータを取得
|
// 空き予約マスタデータを取得
|
||||||
$reserve = DB::table('reserve')
|
$reserve = DB::table('reserve')
|
||||||
->select('reserve_id', 'park_id', 'psection_id')
|
->select('reserve_id', 'park_id', 'ptype_id', 'psection_id')
|
||||||
->where('valid_flag', 1)
|
->where('valid_flag', 1)
|
||||||
->get()
|
->get()
|
||||||
->groupBy('park_id');
|
->groupBy('park_id');
|
||||||
|
|||||||
@ -89,18 +89,31 @@
|
|||||||
<td>
|
<td>
|
||||||
@php
|
@php
|
||||||
$zonesForType = ($zones[$row->park_id] ?? collect())->where('psection_subject', $vehicle);
|
$zonesForType = ($zones[$row->park_id] ?? collect())->where('psection_subject', $vehicle);
|
||||||
@endphp
|
// 空き台数計算
|
||||||
@forelse ($zonesForType as $zone)
|
$hasVacancy = false;
|
||||||
@php
|
foreach ($zonesForType as $zone) {
|
||||||
$reserveCount = ($reserve[$row->park_id] ?? collect())
|
$reserveCount = ($reserve[$row->park_id] ?? collect())
|
||||||
->where('psection_id', $zone->psection_id)
|
->where('psection_id', $zone->psection_id)
|
||||||
|
->where('ptype_id', $zone->ptype_id)
|
||||||
->count();
|
->count();
|
||||||
$vacancy = $zone->zone_tolerance - $zone->zone_number - $reserveCount;
|
$vacancy = $zone->zone_tolerance - $zone->zone_number - $reserveCount;
|
||||||
|
if ($vacancy > 0) {
|
||||||
|
$hasVacancy = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
// 猶予期間判定
|
// 猶予期間判定
|
||||||
$grace = $city_grace_periods[$row->city_id] ?? null;
|
$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;
|
$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;
|
$year = $now->year;
|
||||||
$month = $now->month;
|
$month = $now->month;
|
||||||
$startDay = (int)$grace->update_grace_period_start_date;
|
$startDay = (int)$grace->update_grace_period_start_date;
|
||||||
@ -125,16 +138,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@endphp
|
@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>
|
<button class="btn btn-block btn-sm btn-outline-success btn_82-table btn-popup" data-park-id="{{ $row->park_id }}">定期契約</button>
|
||||||
@elseif (!$inGrace)
|
@elseif (!$inGrace)
|
||||||
<button class="btn btn-block btn-sm btn-outline-danger btn_103-table btn-popup" data-park-id="{{ $row->park_id }}">販売期間外</button>
|
<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)
|
@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>
|
<button class="btn btn-block btn-sm btn-outline-danger btn_103-table btn-popup" data-park-id="{{ $row->park_id }}">空き待ち申込</button>
|
||||||
@endif
|
@endif
|
||||||
@empty
|
@else
|
||||||
<span class="text-muted"></span>
|
<span class="text-muted"></span>
|
||||||
@endforelse
|
@endif
|
||||||
</td>
|
</td>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@ -36,7 +36,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- 空き台数・契約情報 -->
|
<!-- 空き台数・契約情報 -->
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
@foreach($zones as $zone)
|
@php
|
||||||
|
$zonesByPtype = $zones->groupBy('ptype_id');
|
||||||
|
@endphp
|
||||||
|
@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
|
@php
|
||||||
$vacant = $vacancyData[$zone->psection_id . '_' . $zone->ptype_subject] ?? 0;
|
$vacant = $vacancyData[$zone->psection_id . '_' . $zone->ptype_subject] ?? 0;
|
||||||
$grace = $city_grace_periods[$park->city_id] ?? null;
|
$grace = $city_grace_periods[$park->city_id] ?? null;
|
||||||
@ -55,21 +62,26 @@
|
|||||||
|
|
||||||
if ($startDay > $endDay) {
|
if ($startDay > $endDay) {
|
||||||
// 月またぎ
|
// 月またぎ
|
||||||
$start = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $year, $month, $startDay, $startTime));
|
// 前月の開始日~今月の終了日
|
||||||
|
$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;
|
$nextMonth = $month == 12 ? 1 : $month + 1;
|
||||||
$nextYear = $month == 12 ? $year + 1 : $year;
|
$nextYear = $month == 12 ? $year + 1 : $year;
|
||||||
$end = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $nextYear, $nextMonth, $endDay, $endTime));
|
$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 {
|
} else {
|
||||||
// 同月
|
// 同月
|
||||||
$start = \Carbon\Carbon::createFromFormat('Y-m-d H:i', sprintf('%04d-%02d-%02d %s', $year, $month, $startDay, $startTime));
|
$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, $endTime));
|
$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);
|
$isGracePeriod = $now->between($start, $end);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@endphp
|
@endphp
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<strong>{{ $zone->ptype_subject }}</strong><br>
|
{{ $zone->psection_subject }}:空き {{ max(0, $vacant) }}台
|
||||||
{{ $zone->psection_subject }}:空き {{ $vacant }}台
|
|
||||||
@if($isGracePeriod)
|
@if($isGracePeriod)
|
||||||
@if($vacant > 0)
|
@if($vacant > 0)
|
||||||
<button type="button" class="btn btn-success btn-sm btn-contract"
|
<button type="button" class="btn btn-success btn-sm btn-contract"
|
||||||
@ -98,6 +110,9 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">閉じる</button>
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">閉じる</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user