← All changes
|
app/Services/Report/Concerns/Subscription/FutureRenewals.php
+10
-11
1.3.21
→
1.7.1
View file →
| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | namespace FluentCart\App\Services\Report\Concerns\Subscription; |
| 4 | 4 | |
| 5 | 5 | use FluentCart\App\App; |
| 6 | 6 | use FluentCart\App\Services\DateTime\DateTime; |
| 7 | +use FluentCart\App\Services\Payments\PaymentHelper; | |
| 7 | 8 | |
| 8 | 9 | trait FutureRenewals |
| 9 | 10 | { |
| 10 | 11 | public function getFutureRenewals(array $params) |
| @@ -133,8 +134,12 @@ | ||
| 133 | 134 | $renewalCount = 0; |
| 134 | 135 | $currentBilling = clone $nextBilling; |
| 135 | 136 | $intervalDays = $this->getIntervalDays($subscription->billing_interval); |
| 136 | 137 | |
| 138 | + if ($intervalDays < 1) { // unresolved interval would never advance the loop | |
| 139 | + return 0; | |
| 140 | + } | |
| 141 | + | |
| 137 | 142 | while ($currentBilling <= $periodEnd) { |
| 138 | 143 | if ($currentBilling >= $periodStart) { |
| 139 | 144 | $renewalCount++; |
| 140 | 145 | |
| @@ -154,19 +159,9 @@ | ||
| 154 | 159 | * Convert billing interval to days |
| 155 | 160 | */ |
| 156 | 161 | private function getIntervalDays($interval) |
| 157 | 162 | { |
| 158 | - $intervals = [ | |
| 159 | - 'daily' => 1, | |
| 160 | - 'weekly' => 7, | |
| 161 | - 'monthly' => 30, | |
| 162 | - 'quarterly' => 90, | |
| 163 | - 'yearly' => 365, | |
| 164 | - 'biweekly' => 14, | |
| 165 | - 'bimonthly' => 60, | |
| 166 | - ]; | |
| 167 | - | |
| 168 | - return $intervals[$interval] ?? 30; // Default to monthly | |
| 163 | + return PaymentHelper::getIntervalDays($interval); | |
| 169 | 164 | } |
| 170 | 165 | |
| 171 | 166 | /** |
| 172 | 167 | * Get actual renewal dates for a subscription within the period |
| @@ -196,8 +191,12 @@ | ||
| 196 | 191 | |
| 197 | 192 | $currentBilling = clone $nextBilling; |
| 198 | 193 | $intervalDays = $this->getIntervalDays($subscription->billing_interval); |
| 199 | 194 | $renewalCount = 0; |
| 195 | + | |
| 196 | + if ($intervalDays < 1) { // unresolved interval would never advance the loop | |
| 197 | + return $renewalDates; | |
| 198 | + } | |
| 200 | 199 | |
| 201 | 200 | while ($currentBilling <= $periodEnd) { |
| 202 | 201 | if ($currentBilling >= $periodStart) { |
| 203 | 202 | $renewalDates[] = clone $currentBilling; |