feat(plans): enhance plan management with dynamic providers, improved UI, and bug fixes
Dynamic Provider Integration: - Replace hardcoded provider arrays with database-driven payment_providers lookup - Display provider status (Active/Inactive) in selection dropdowns - Add provider_variant_id and provider_product_id input fields to plan configuration - Update EditPlan and SubscriptionForm with dynamic provider selection - Add empty state handling with helpful guidance when no providers exist UI/UX Improvements: - Format billing_cycle_days to readable text (Daily, Weekly, Monthly, Quarterly, Annually) - Add color-coded badges for billing cycle frequency - Fix plan_providers and plan_feature_limits count display with eager loading - Implement intelligent color coding for count indicators - Add visual status indicators for provider availability Database Compatibility: - Fix SQLite strftime() compatibility across all dashboard widgets - Fix CAST AS REAL syntax in ChurnAnalysis widget - Add database-agnostic date and cast expression methods - Support MySQL, SQLite, PostgreSQL, and SQL Server Bug Fixes: - Fix null reference error in SubscriptionForm provider_data access - Add null safety checks for new subscription creation - Optimize queries with withCount() to prevent N+1 issues Performance Optimizations: - Add eager loading with withCount() for relationship counts - Optimize plan provider and feature limit queries - Prevent N+1 query issues in resource tables BREAKING CHANGE: Plan provider configuration now uses dynamic provider options from payment_providers table instead of hardcoded list.
This commit is contained in:
@@ -146,10 +146,34 @@ class PlanResource extends Resource
|
||||
->money('USD')
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('billing_cycle_display')
|
||||
Tables\Columns\TextColumn::make('billing_cycle_days')
|
||||
->label('Billing Cycle')
|
||||
->badge()
|
||||
->color('primary'),
|
||||
->color(fn (int $state): string => match ($state) {
|
||||
1 => 'success', // Daily - green
|
||||
7 => 'info', // Weekly - blue
|
||||
14 => 'primary', // Bi-weekly - primary blue
|
||||
30 => 'warning', // Monthly - orange
|
||||
60 => 'gray', // Bi-monthly - gray
|
||||
90 => 'purple', // Quarterly - purple
|
||||
180 => 'danger', // Semi-annually - red
|
||||
365 => 'primary', // Annually - primary blue
|
||||
730 => 'gray', // Biennially - gray
|
||||
default => 'gray' // Custom cycles - gray
|
||||
})
|
||||
->formatStateUsing(fn (int $state): string => match ($state) {
|
||||
1 => 'Daily',
|
||||
7 => 'Weekly',
|
||||
14 => 'Bi-weekly',
|
||||
30 => 'Monthly',
|
||||
60 => 'Bi-monthly',
|
||||
90 => 'Quarterly',
|
||||
180 => 'Semi-annually',
|
||||
365 => 'Annually',
|
||||
730 => 'Biennially',
|
||||
default => "{$state} days"
|
||||
})
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\IconColumn::make('is_active')
|
||||
->label('Active')
|
||||
@@ -157,19 +181,29 @@ class PlanResource extends Resource
|
||||
->trueColor('success')
|
||||
->falseColor('danger'),
|
||||
|
||||
Tables\Columns\TextColumn::make('planProviders_count')
|
||||
Tables\Columns\TextColumn::make('plan_providers_count')
|
||||
->label('Providers')
|
||||
->counts('planProviders')
|
||||
->getStateUsing(fn ($record) => $record->plan_providers_count ?? 0)
|
||||
->badge()
|
||||
->color('info')
|
||||
->sortable(false),
|
||||
->color(fn ($record) => match (true) {
|
||||
$record->plan_providers_count === 0 => 'danger',
|
||||
$record->plan_providers_count === 1 => 'warning',
|
||||
$record->plan_providers_count >= 3 => 'success',
|
||||
default => 'info'
|
||||
})
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('planFeatureLimits_count')
|
||||
Tables\Columns\TextColumn::make('plan_feature_limits_count')
|
||||
->label('Features')
|
||||
->counts('planFeatureLimits')
|
||||
->getStateUsing(fn ($record) => $record->plan_feature_limits_count ?? 0)
|
||||
->badge()
|
||||
->color('warning')
|
||||
->sortable(false),
|
||||
->color(fn ($record) => match (true) {
|
||||
$record->plan_feature_limits_count === 0 => 'danger',
|
||||
$record->plan_feature_limits_count >= 5 => 'success',
|
||||
$record->plan_feature_limits_count >= 3 => 'info',
|
||||
default => 'warning'
|
||||
})
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('sort_order')
|
||||
->label('Order')
|
||||
@@ -235,6 +269,15 @@ class PlanResource extends Resource
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withCount([
|
||||
'planProviders',
|
||||
'planFeatureLimits',
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user