PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.5
Yatra – Travel Booking & Tour Operator Software v3.0.5
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / app / Services / CapacityService.php

CapacityService.php in Yatra – Travel Booking & Tour Operator Software 3.0.5, at app/Services/CapacityService.php

70 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Services;
6
7 use Yatra\Repositories\AvailabilityRepository;
8 use Yatra\Repositories\RecurringAvailabilityRepository;
9 use Yatra\Repositories\TripRepository;
10
11 class CapacityService
12 {
13 private AvailabilityRepository $availabilityRepository;
14 private RecurringAvailabilityRepository $recurringAvailabilityRepository;
15 private TripRepository $tripRepository;
16
17 public function __construct(
18 ?AvailabilityRepository $availabilityRepository = null,
19 ?RecurringAvailabilityRepository $recurringAvailabilityRepository = null,
20 ?TripRepository $tripRepository = null
21 ) {
22 $this->availabilityRepository = $availabilityRepository ?? new AvailabilityRepository();
23 $this->recurringAvailabilityRepository = $recurringAvailabilityRepository ?? new RecurringAvailabilityRepository();
24 $this->tripRepository = $tripRepository ?? new TripRepository();
25 }
26
27 /**
28 * Get capacity for a specific trip and date based on priority
29 *
30 * @param int $tripId Trip ID
31 * @param string $date Date in YYYY-MM-DD format
32 * @return int Maximum capacity
33 */
34 public function getCapacityForDate(int $tripId, string $date): int
35 {
36 // 1. Check Availability Date first (specific date overrides)
37 $availability = $this->availabilityRepository->findByTripIdAndDate($tripId, $date);
38 if ($availability && isset($availability->seats_total) && $availability->seats_total > 0) {
39 return (int) $availability->seats_total;
40 }
41
42 // 2. Check Recurring Availability Rules
43 $recurringRules = $this->recurringAvailabilityRepository->findActiveRulesForDate($tripId, $date);
44 if (!empty($recurringRules)) {
45 // Sort by priority (if applicable) and get the first matching rule
46 $matchingRule = reset($recurringRules);
47 $seats = (int) ($matchingRule->seats_total ?? 0);
48 if ($seats <= 0 && !empty($matchingRule->capacity_value)) {
49 $capType = $matchingRule->capacity_type ?? 'fixed';
50 if ($capType === 'fixed') {
51 $seats = (int) $matchingRule->capacity_value;
52 }
53 }
54 if ($seats > 0) {
55 return $seats;
56 }
57 }
58
59 // 3. Fall back to trip's default capacity (column is max_travelers; max_travellers kept for legacy rows)
60 $trip = $this->tripRepository->find($tripId);
61 if (!$trip) {
62 return 0;
63 }
64
65 $cap = (int) ($trip->max_travelers ?? $trip->max_travellers ?? 0);
66
67 return $cap > 0 ? $cap : 0;
68 }
69 }
70