Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/Models/Concerns/HasSubscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,12 @@ protected function consumeNotQuotaFeature(Feature $feature, ?float $consumption
: null;

$featureConsumption = $this->featureConsumptions()
->make([
'consumption' => $consumption,
'expired_at' => $consumptionExpiration,
])
->feature()
->associate($feature);
->whereFeatureId($feature->id)
->firstOrNew();

$featureConsumption->feature()->associate($feature);
$featureConsumption->consumption += $consumption;
$featureConsumption->expired_at = $consumptionExpiration;
$featureConsumption->save();

return $featureConsumption;
Expand Down Expand Up @@ -327,9 +326,12 @@ protected function getSubscriptionChargesForAFeature(Model $feature): float
return 0;
}

return $subscriptionFeature
->pivot
->charges;
$charges = $subscriptionFeature->pivot->charges;
if ($charges == -1) {
return INF;
}

return $charges;
}

protected function getTicketChargesForAFeature(Model $feature): float
Expand All @@ -341,9 +343,12 @@ protected function getTicketChargesForAFeature(Model $feature): float
return 0;
}

return $ticketFeature
->tickets
->sum('charges');
$charges = $ticketFeature->tickets->sum('charges');
if ($charges === -1) {
return INF;
}

return $charges;
}

public function getFeature(string $featureName): ?Feature
Expand Down