chore: fix mrr calculation and grid import
This commit is contained in:
@@ -264,6 +264,34 @@ class Plan extends Model
|
||||
return $this->monthly_billing ? 'Monthly' : 'Yearly';
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Monthly Recurring Revenue (MRR) for this plan
|
||||
*/
|
||||
public function calculateMRR(): float
|
||||
{
|
||||
if (! $this->price) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Use the new billing cycle system if available
|
||||
if ($this->billing_cycle_days) {
|
||||
return ($this->price / $this->billing_cycle_days) * 30;
|
||||
}
|
||||
|
||||
// Fallback to legacy system
|
||||
$cycleDays = $this->monthly_billing ? 30 : 365;
|
||||
|
||||
return ($this->price / $cycleDays) * 30;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get monthly price attribute for compatibility
|
||||
*/
|
||||
public function getMonthlyPriceAttribute(): float
|
||||
{
|
||||
return $this->calculateMRR();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plan metadata value
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user