| @@ -241,9 +241,24 @@ | ||
| 241 | 241 | if ($correctCapacity > 0 && $d->max_capacity !== $correctCapacity) { |
| 242 | 242 | $departureRepo->update($d->id, ['max_capacity' => $correctCapacity]); |
| 243 | 243 | $d->max_capacity = $correctCapacity; |
| 244 | 244 | } |
| 245 | - | |
| 245 | + | |
| 246 | + // Promote a departure that has taken place to 'past' so a | |
| 247 | + // completed departure is never shown with (or hidden behind) a | |
| 248 | + // stale 'upcoming'/'full' status — the daily cron may not have | |
| 249 | + // run. Cancelled/trashed departures are left as-is. This keeps | |
| 250 | + // the status badge and the tab counts date-accurate. | |
| 251 | + if (!in_array($d->status, ['cancelled', 'trash', 'past'], true)) { | |
| 252 | + $checkDate = (!empty($d->end_date) && $d->end_date !== '0000-00-00') | |
| 253 | + ? $d->end_date | |
| 254 | + : ((!empty($d->start_date) && $d->start_date !== '0000-00-00') ? $d->start_date : $d->date); | |
| 255 | + if (!empty($checkDate) && $checkDate < date('Y-m-d')) { | |
| 256 | + $departureRepo->update($d->id, ['status' => 'past']); | |
| 257 | + $d->status = 'past'; | |
| 258 | + } | |
| 259 | + } | |
| 260 | + | |
| 246 | 261 | $departureArray = $d->toArray(); |
| 247 | 262 | |
| 248 | 263 | // Add trip information |
| 249 | 264 | if ($trip) { |
| @@ -621,13 +636,47 @@ | ||
| 621 | 636 | $processed = array_map(function ($d) use ($tripRepository, $bookingDepartureRepo, $travellerRepo, $bookingRepo, $capacityService, $departureRepo) { |
| 622 | 637 | // Sync capacity from availability before returning |
| 623 | 638 | $date = $d->start_date ?: $d->date; |
| 624 | 639 | $correctCapacity = $capacityService->getCapacityForDate($d->trip_id, $date, $d->time ?? null); |
| 625 | - if ($correctCapacity > 0 && $d->max_capacity !== $correctCapacity) { | |
| 626 | - $departureRepo->update($d->id, ['max_capacity' => $correctCapacity]); | |
| 627 | - $d->max_capacity = $correctCapacity; | |
| 640 | + if ($correctCapacity > 0) { | |
| 641 | + if ((int) $d->max_capacity !== $correctCapacity) { | |
| 642 | + $departureRepo->update($d->id, ['max_capacity' => $correctCapacity]); | |
| 643 | + $d->max_capacity = $correctCapacity; | |
| 644 | + } | |
| 645 | + } elseif ((int) $d->max_capacity >= 9999) { | |
| 646 | + // Normalise a legacy "unlimited"/junk capacity sentinel (e.g. | |
| 647 | + // 9999/11111) to the canonical unlimited value 0, so it isn't | |
| 648 | + // shown as a huge literal number here while the dashboard renders | |
| 649 | + // >= 9999 as 0 — the two disagreeing on capacity and occupancy. | |
| 650 | + // | |
| 651 | + // Deliberately heal to 0 (NOT the trip's max_travelers): 0 means | |
| 652 | + // "unlimited" to both the capacity guard (incrementBookedCount) | |
| 653 | + // and Departure::calculateStatus(), so healing can never flip an | |
| 654 | + // already (over-)booked departure to 'full' — which capping to a | |
| 655 | + // smaller number would, and 'full' departures drop out of the | |
| 656 | + // dashboard's upcoming view. This keeps the sentinel's original | |
| 657 | + // "unlimited" meaning while making both surfaces agree. | |
| 658 | + if ((int) $d->max_capacity !== 0) { | |
| 659 | + $departureRepo->update($d->id, ['max_capacity' => 0]); | |
| 660 | + $d->max_capacity = 0; | |
| 661 | + } | |
| 628 | 662 | } |
| 629 | - | |
| 663 | + | |
| 664 | + // Promote a departure that has taken place to 'past' so a completed | |
| 665 | + // departure is never shown with (or hidden behind) a stale | |
| 666 | + // 'upcoming'/'full' status — the daily cron may not have run. | |
| 667 | + // Cancelled/trashed departures are left as-is. Keeps the status | |
| 668 | + // badge and the dashboard/tab counts date-accurate. | |
| 669 | + if (!in_array($d->status, ['cancelled', 'trash', 'past'], true)) { | |
| 670 | + $checkDate = (!empty($d->end_date) && $d->end_date !== '0000-00-00') | |
| 671 | + ? $d->end_date | |
| 672 | + : ((!empty($d->start_date) && $d->start_date !== '0000-00-00') ? $d->start_date : $d->date); | |
| 673 | + if (!empty($checkDate) && $checkDate < date('Y-m-d')) { | |
| 674 | + $departureRepo->update($d->id, ['status' => 'past']); | |
| 675 | + $d->status = 'past'; | |
| 676 | + } | |
| 677 | + } | |
| 678 | + | |
| 630 | 679 | $departureArray = $d->toArray(); |
| 631 | 680 | |
| 632 | 681 | // Add trip information |
| 633 | 682 | $trip = $tripRepository->find($d->trip_id); |