chore: fix mrr calculation and grid import

This commit is contained in:
idevakk
2025-11-21 12:41:54 -08:00
parent 0baacdc386
commit 38ae2770ea
4 changed files with 114 additions and 33 deletions

View File

@@ -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
*/