Central panel SaaS upgrade — Plans/Subscriptions/SuperAdmins/Detail page
Models & migrations: - subscriptions table (company, plan, period, amount, status, dates, invoice) - super_admins: role enum (owner/admin/support/sales/finance) + phone + notes - Subscription model with STATUSES/PERIODS/PAYMENT_METHODS + invoice number generator + extends company.active_until on mark_paid - Company model: subscriptions() + latestSubscription() relations - SuperAdmin model: role helpers (isOwner, canManageBilling, canManageTenants) Filament Central panel: - PlanResource (CRUD, features checklist, limits per plan, abonati count badge) - SubscriptionResource (CRUD, mark_paid action, navigation badge for overdue) - SuperAdminResource (CRUD, reset password, toggle 2FA, can't self-delete) - ViewCompany page with live stats (users/clients/vehicles/WO/parts/revenue/ storage/last_login + days_until_expiry), subscriptions history table, config snapshot, action buttons (open/issue invoice/upload logo/suspend) - CompanyResource: row click → view, openUrlInNewTab action, recordTitleAttribute, empty state, view route registered - PlatformStats widget upgraded: 6 cards (incl. MRR realized this month, overdue invoices count, click-through to filtered tables) - RevenueChart: 12-month MRR line chart - RecentTenants: latest 8 tenants with click-through - PendingPayments: pending+overdue invoices table - Database notifications enabled + Cmd+K global search - HEAD_END render hook: PWA manifest + theme color + emoji favicon - /admin-manifest.json route Seeder: - Plans aligned with new FEATURE_OPTIONS (kanban/pdf/reports/ai/api/reverb/etc) - 4 plans: Free / Basic / Pro / Enterprise (with proper limits) - SuperAdmin gets role='owner' - Demo subscription for psauto on Pro plan, marked paid this month
This commit is contained in:
@@ -25,6 +25,15 @@ class CompanyResource extends Resource
|
||||
|
||||
protected static ?string $pluralModelLabel = 'companii';
|
||||
|
||||
protected static ?int $navigationSort = 10;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['slug', 'name', 'display_name', 'city', 'phone', 'email'];
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
@@ -123,7 +132,16 @@ class CompanyResource extends Resource
|
||||
'suspended' => 'Suspendat', 'archived' => 'Arhivat',
|
||||
]),
|
||||
])
|
||||
->recordUrl(fn (Company $r) => CompanyResource::getUrl('view', ['record' => $r]))
|
||||
->actions([
|
||||
Actions\ViewAction::make()
|
||||
->url(fn (Company $r) => CompanyResource::getUrl('view', ['record' => $r])),
|
||||
Actions\Action::make('open_tenant')
|
||||
->label('Deschide')
|
||||
->icon('heroicon-m-arrow-top-right-on-square')
|
||||
->color('primary')
|
||||
->url(fn (Company $r) => $r->url('/app'))
|
||||
->openUrlInNewTab(),
|
||||
Actions\Action::make('suspend')
|
||||
->label('Suspendă')
|
||||
->icon('heroicon-m-no-symbol')
|
||||
@@ -141,6 +159,9 @@ class CompanyResource extends Resource
|
||||
Actions\EditAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
])
|
||||
->emptyStateHeading('Niciun tenant încă')
|
||||
->emptyStateDescription('Adaugă primul client SaaS folosind butonul „Adaugă companie" — se va crea un tenant nou cu admin pe `<slug>.service.mir.md/app`.')
|
||||
->emptyStateIcon('heroicon-o-building-office-2')
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
@@ -149,6 +170,7 @@ class CompanyResource extends Resource
|
||||
return [
|
||||
'index' => Pages\ListCompanies::route('/'),
|
||||
'create' => Pages\CreateCompany::route('/create'),
|
||||
'view' => Pages\ViewCompany::route('/{record}'),
|
||||
'edit' => Pages\EditCompany::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources\CompanyResource\Pages;
|
||||
|
||||
use App\Filament\Central\Resources\CompanyResource;
|
||||
use App\Models\Central\Company;
|
||||
use App\Models\Central\Subscription;
|
||||
use App\Models\Tenant\Client;
|
||||
use App\Models\Tenant\Part;
|
||||
use App\Models\Tenant\Payment;
|
||||
use App\Models\Tenant\User as TenantUser;
|
||||
use App\Models\Tenant\Vehicle;
|
||||
use App\Models\Tenant\WorkOrder;
|
||||
use App\Tenancy\TenantManager;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\Page;
|
||||
|
||||
class ViewCompany extends Page
|
||||
{
|
||||
protected static string $resource = CompanyResource::class;
|
||||
|
||||
protected string $view = 'filament.central.resources.company.view';
|
||||
|
||||
public Company $record;
|
||||
|
||||
public function mount(int|string $record): void
|
||||
{
|
||||
$this->record = Company::with(['plan', 'subscriptions' => fn ($q) => $q->latest('period_end')->limit(10)])->findOrFail($record);
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->record->display_name ?? $this->record->name;
|
||||
}
|
||||
|
||||
public function getStats(): array
|
||||
{
|
||||
// Set tenant context to query scoped tables.
|
||||
app(TenantManager::class)->setCurrent($this->record);
|
||||
app(\Spatie\Permission\PermissionRegistrar::class)
|
||||
->setPermissionsTeamId($this->record->id);
|
||||
|
||||
$stats = [
|
||||
'users' => TenantUser::count(),
|
||||
'clients' => Client::count(),
|
||||
'vehicles' => Vehicle::count(),
|
||||
'work_orders' => WorkOrder::count(),
|
||||
'work_orders_open' => WorkOrder::whereNotIn('status', ['done', 'cancelled'])->count(),
|
||||
'parts' => Part::count(),
|
||||
'parts_low_stock' => Part::where('is_active', true)
|
||||
->whereColumn('stock', '<=', 'low_stock_threshold')
|
||||
->where('stock', '>', 0)
|
||||
->count(),
|
||||
'revenue_this_month' => (float) Payment::whereYear('paid_at', date('Y'))
|
||||
->whereMonth('paid_at', date('m'))->sum('amount'),
|
||||
'revenue_last_month' => (float) Payment::whereYear('paid_at', now()->subMonth()->year)
|
||||
->whereMonth('paid_at', now()->subMonth()->month)->sum('amount'),
|
||||
'last_login' => TenantUser::whereNotNull('last_login_at')->max('last_login_at'),
|
||||
'storage_mb' => $this->calculateStorageMb(),
|
||||
];
|
||||
|
||||
app(TenantManager::class)->setCurrent(null);
|
||||
return $stats;
|
||||
}
|
||||
|
||||
private function calculateStorageMb(): float
|
||||
{
|
||||
try {
|
||||
$bytes = (int) \DB::table('media')
|
||||
->where('model_type', \App\Models\Central\Company::class)
|
||||
->where('model_id', $this->record->id)
|
||||
->sum('size');
|
||||
return round($bytes / 1024 / 1024, 2);
|
||||
} catch (\Throwable) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDaysUntilExpiry(): ?int
|
||||
{
|
||||
$until = $this->record->active_until ?? $this->record->trial_ends_at;
|
||||
if (! $until) return null;
|
||||
$diff = now()->diffInDays($until, false);
|
||||
return (int) $diff;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('view_as')
|
||||
->label('Deschide tenantul')
|
||||
->icon('heroicon-m-arrow-top-right-on-square')
|
||||
->color('primary')
|
||||
->url(fn () => $this->record->url('/app'))
|
||||
->openUrlInNewTab(),
|
||||
Actions\Action::make('issue_invoice')
|
||||
->label('Generează factură')
|
||||
->icon('heroicon-m-document-plus')
|
||||
->color('success')
|
||||
->visible(fn () => (bool) $this->record->plan_id)
|
||||
->schema([
|
||||
Forms\Components\Select::make('period')->options(\App\Models\Central\Subscription::PERIODS)->default('monthly')->required(),
|
||||
])
|
||||
->action(function (array $data) {
|
||||
$plan = $this->record->plan;
|
||||
if (! $plan) return;
|
||||
$start = today();
|
||||
$end = $data['period'] === 'yearly' ? $start->copy()->addYear() : $start->copy()->addMonth();
|
||||
$sub = Subscription::create([
|
||||
'company_id' => $this->record->id,
|
||||
'plan_id' => $plan->id,
|
||||
'period' => $data['period'],
|
||||
'amount' => $data['period'] === 'yearly' ? $plan->price_yearly : $plan->price_monthly,
|
||||
'currency' => $plan->currency,
|
||||
'status' => 'pending',
|
||||
'period_start' => $start,
|
||||
'period_end' => $end,
|
||||
'due_at' => $start->copy()->addDays(7),
|
||||
'invoice_number' => Subscription::generateInvoiceNumber(),
|
||||
]);
|
||||
Notification::make()
|
||||
->title('Factură generată: ' . $sub->invoice_number)
|
||||
->body('Suma: ' . number_format($sub->amount, 2) . ' ' . $sub->currency)
|
||||
->success()->send();
|
||||
$this->dispatch('$refresh');
|
||||
}),
|
||||
Actions\Action::make('upload_logo')
|
||||
->label('Logo')
|
||||
->icon('heroicon-m-photo')
|
||||
->color('gray')
|
||||
->schema([
|
||||
Forms\Components\FileUpload::make('logo')
|
||||
->image()
|
||||
->imageEditor()
|
||||
->disk('public')
|
||||
->directory('central-uploads')
|
||||
->maxSize(2048)
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data) {
|
||||
if (empty($data['logo'])) return;
|
||||
$abs = \Illuminate\Support\Facades\Storage::disk('public')->path($data['logo']);
|
||||
if (file_exists($abs)) {
|
||||
$this->record->clearMediaCollection('logo');
|
||||
$this->record->addMedia($abs)->preservingOriginal()->toMediaCollection('logo');
|
||||
@unlink($abs);
|
||||
Notification::make()->title('Logo actualizat')->success()->send();
|
||||
}
|
||||
}),
|
||||
Actions\Action::make('edit')
|
||||
->label('Editează')
|
||||
->icon('heroicon-m-pencil')
|
||||
->url(fn () => CompanyResource::getUrl('edit', ['record' => $this->record])),
|
||||
Actions\Action::make('suspend')
|
||||
->label('Suspendă')->icon('heroicon-m-no-symbol')->color('danger')
|
||||
->visible(fn () => in_array($this->record->status, ['active', 'trial']))
|
||||
->requiresConfirmation()
|
||||
->action(function () {
|
||||
app(\App\Services\CompanyProvisioner::class)->suspend($this->record);
|
||||
Notification::make()->title('Tenant suspendat.')->success()->send();
|
||||
$this->dispatch('$refresh');
|
||||
}),
|
||||
Actions\Action::make('activate')
|
||||
->label('Reactivează')->icon('heroicon-m-check-circle')->color('success')
|
||||
->visible(fn () => in_array($this->record->status, ['suspended', 'expired']))
|
||||
->requiresConfirmation()
|
||||
->action(function () {
|
||||
app(\App\Services\CompanyProvisioner::class)->reactivate($this->record);
|
||||
Notification::make()->title('Tenant activat.')->success()->send();
|
||||
$this->dispatch('$refresh');
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources;
|
||||
|
||||
use App\Filament\Central\Resources\PlanResource\Pages;
|
||||
use App\Models\Central\Plan;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class PlanResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Plan::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationLabel = 'Planuri';
|
||||
|
||||
protected static ?string $modelLabel = 'plan';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'planuri';
|
||||
|
||||
protected static ?int $navigationSort = 20;
|
||||
|
||||
public const FEATURE_OPTIONS = [
|
||||
'kanban' => 'Kanban WO',
|
||||
'reports' => 'Rapoarte avansate',
|
||||
'ai' => 'Asistent AI',
|
||||
'pdf' => 'Generare PDF',
|
||||
'reverb' => 'WebSocket real-time',
|
||||
'api' => 'REST API + tokens',
|
||||
'multi_user' => 'Multi-user (>1 cont)',
|
||||
'white_label' => 'White-label complet',
|
||||
'priority_support' => 'Suport prioritar',
|
||||
'custom_domain' => 'Domeniu propriu',
|
||||
];
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Schemas\Components\Section::make('Identificare')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('slug')
|
||||
->required()->alphaDash()->unique(ignoreRecord: true)
|
||||
->dehydrateStateUsing(fn ($s) => strtolower((string) $s))
|
||||
->extraInputAttributes(['style' => 'text-transform:lowercase']),
|
||||
Forms\Components\TextInput::make('name')->required()->maxLength(60),
|
||||
Forms\Components\Toggle::make('is_active')->label('Activ')->default(true),
|
||||
Forms\Components\Toggle::make('is_public')->label('Public (afișat la signup)')->default(true),
|
||||
]),
|
||||
Schemas\Components\Section::make('Preț')
|
||||
->columns(3)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('price_monthly')->label('Preț lunar')->numeric()->required()->suffix(fn (Forms\Get $get) => $get('currency') ?? 'MDL'),
|
||||
Forms\Components\TextInput::make('price_yearly')->label('Preț anual')->numeric()->helperText('De obicei 10× preț lunar (2 luni gratis).')->suffix(fn (Forms\Get $get) => $get('currency') ?? 'MDL'),
|
||||
Forms\Components\Select::make('currency')->options(['MDL' => 'MDL', 'EUR' => 'EUR', 'USD' => 'USD'])->default('MDL'),
|
||||
]),
|
||||
Schemas\Components\Section::make('Funcționalități incluse')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\CheckboxList::make('features')
|
||||
->options(self::FEATURE_OPTIONS)
|
||||
->columns(2)
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
Schemas\Components\Section::make('Limite')
|
||||
->columns(3)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('limits.max_users')->label('Max useri')->numeric()->placeholder('∞'),
|
||||
Forms\Components\TextInput::make('limits.max_clients')->label('Max clienți')->numeric()->placeholder('∞'),
|
||||
Forms\Components\TextInput::make('limits.max_vehicles')->label('Max mașini')->numeric()->placeholder('∞'),
|
||||
Forms\Components\TextInput::make('limits.max_work_orders_month')->label('Max fișe/lună')->numeric()->placeholder('∞'),
|
||||
Forms\Components\TextInput::make('limits.storage_mb')->label('Storage (MB)')->numeric()->placeholder('∞'),
|
||||
Forms\Components\TextInput::make('limits.ai_messages_month')->label('Mesaje AI/lună')->numeric()->placeholder('∞'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')->searchable()->sortable(),
|
||||
Tables\Columns\TextColumn::make('price_monthly')
|
||||
->money(fn ($r) => $r->currency)
|
||||
->label('Lunar')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('price_yearly')
|
||||
->money(fn ($r) => $r->currency)
|
||||
->label('Anual'),
|
||||
Tables\Columns\TextColumn::make('companies_count')
|
||||
->counts('companies')
|
||||
->label('Abonați')
|
||||
->badge()
|
||||
->color('primary'),
|
||||
Tables\Columns\TextColumn::make('features')
|
||||
->label('Funcționalități')
|
||||
->formatStateUsing(fn ($s) => is_array($s) ? count($s) . ' incluse' : '—')
|
||||
->badge(),
|
||||
Tables\Columns\IconColumn::make('is_active')->boolean()->label('Activ'),
|
||||
Tables\Columns\IconColumn::make('is_public')->boolean()->label('Public'),
|
||||
])
|
||||
->actions([
|
||||
Actions\EditAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
])
|
||||
->emptyStateHeading('Niciun plan definit')
|
||||
->emptyStateDescription('Creează planuri (ex: Free, Basic, Pro) și atribuie-le companiilor.')
|
||||
->defaultSort('price_monthly');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListPlans::route('/'),
|
||||
'create' => Pages\CreatePlan::route('/create'),
|
||||
'edit' => Pages\EditPlan::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources\PlanResource\Pages;
|
||||
|
||||
use App\Filament\Central\Resources\PlanResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePlan extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PlanResource::class;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources\PlanResource\Pages;
|
||||
|
||||
use App\Filament\Central\Resources\PlanResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPlan extends EditRecord
|
||||
{
|
||||
protected static string $resource = PlanResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\DeleteAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources\PlanResource\Pages;
|
||||
|
||||
use App\Filament\Central\Resources\PlanResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPlans extends ListRecords
|
||||
{
|
||||
protected static string $resource = PlanResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\CreateAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources;
|
||||
|
||||
use App\Filament\Central\Resources\SubscriptionResource\Pages;
|
||||
use App\Models\Central\Company;
|
||||
use App\Models\Central\Plan;
|
||||
use App\Models\Central\Subscription;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class SubscriptionResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Subscription::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-credit-card';
|
||||
|
||||
protected static ?string $navigationLabel = 'Facturi & abonamente';
|
||||
|
||||
protected static ?string $modelLabel = 'factură';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'facturi';
|
||||
|
||||
protected static ?int $navigationSort = 30;
|
||||
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
$overdue = static::$model::where('status', 'overdue')->count();
|
||||
return $overdue > 0 ? (string) $overdue : null;
|
||||
}
|
||||
|
||||
public static function getNavigationBadgeColor(): ?string { return 'danger'; }
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Schemas\Components\Section::make('Companie & plan')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\Select::make('company_id')
|
||||
->label('Companie')
|
||||
->options(fn () => Company::orderBy('name')->pluck('name', 'id'))
|
||||
->required()->searchable()->live(),
|
||||
Forms\Components\Select::make('plan_id')
|
||||
->label('Plan')
|
||||
->options(fn () => Plan::pluck('name', 'id'))
|
||||
->required()->searchable()->live()
|
||||
->afterStateUpdated(function ($state, Forms\Set $set, Forms\Get $get) {
|
||||
if (! $state) return;
|
||||
$plan = Plan::find($state);
|
||||
if (! $plan) return;
|
||||
$period = $get('period') ?? 'monthly';
|
||||
$set('amount', $period === 'yearly' ? $plan->price_yearly : $plan->price_monthly);
|
||||
$set('currency', $plan->currency);
|
||||
}),
|
||||
Forms\Components\Select::make('period')
|
||||
->options(Subscription::PERIODS)->default('monthly')->required()->live()
|
||||
->afterStateUpdated(function ($state, Forms\Set $set, Forms\Get $get) {
|
||||
$plan = Plan::find($get('plan_id'));
|
||||
if (! $plan) return;
|
||||
$set('amount', $state === 'yearly' ? $plan->price_yearly : $plan->price_monthly);
|
||||
// Auto-fill period_end based on period
|
||||
$start = $get('period_start') ?? now()->toDateString();
|
||||
$end = $state === 'yearly'
|
||||
? \Carbon\Carbon::parse($start)->addYear()->toDateString()
|
||||
: \Carbon\Carbon::parse($start)->addMonth()->toDateString();
|
||||
$set('period_end', $end);
|
||||
}),
|
||||
Forms\Components\Select::make('status')
|
||||
->options(Subscription::STATUSES)->default('pending')->required(),
|
||||
]),
|
||||
Schemas\Components\Section::make('Sumă')
|
||||
->columns(3)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('amount')->numeric()->required()->suffix(fn (Forms\Get $get) => $get('currency') ?? 'MDL'),
|
||||
Forms\Components\Select::make('currency')->options(['MDL' => 'MDL', 'EUR' => 'EUR', 'USD' => 'USD'])->default('MDL'),
|
||||
Forms\Components\Select::make('payment_method')
|
||||
->options(Subscription::PAYMENT_METHODS),
|
||||
]),
|
||||
Schemas\Components\Section::make('Perioadă')
|
||||
->columns(3)
|
||||
->schema([
|
||||
Forms\Components\DatePicker::make('period_start')->required()->default(today()),
|
||||
Forms\Components\DatePicker::make('period_end')->required(),
|
||||
Forms\Components\DateTimePicker::make('due_at')->label('Scadent la'),
|
||||
Forms\Components\DateTimePicker::make('paid_at')->label('Plătit la'),
|
||||
]),
|
||||
Schemas\Components\Section::make('Detalii')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('invoice_number')->label('Nr. factură')->placeholder('auto-generat')->maxLength(30),
|
||||
Forms\Components\TextInput::make('reference')->label('Referință (Stripe id, transfer)')->maxLength(100),
|
||||
Forms\Components\Textarea::make('notes')->columnSpanFull()->rows(2),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('invoice_number')
|
||||
->label('Factură')
|
||||
->placeholder(fn ($r) => '—')
|
||||
->copyable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('company.name')
|
||||
->label('Companie')
|
||||
->searchable()
|
||||
->url(fn ($r) => route('filament.central.resources.companies.edit', ['record' => $r->company_id])),
|
||||
Tables\Columns\TextColumn::make('plan.name')->label('Plan')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('period')
|
||||
->formatStateUsing(fn ($s) => Subscription::PERIODS[$s] ?? $s)
|
||||
->badge(),
|
||||
Tables\Columns\TextColumn::make('amount')
|
||||
->money(fn ($r) => $r->currency)
|
||||
->sortable()
|
||||
->weight('bold'),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn ($s) => Subscription::STATUSES[$s] ?? $s)
|
||||
->color(fn ($s) => match ($s) {
|
||||
'paid' => 'success',
|
||||
'overdue' => 'danger',
|
||||
'pending' => 'warning',
|
||||
'cancelled', 'refunded' => 'gray',
|
||||
default => 'primary',
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('period_end')->label('Până la')->date(),
|
||||
Tables\Columns\TextColumn::make('paid_at')->label('Plătit')->date()->placeholder('—'),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('status')->options(Subscription::STATUSES),
|
||||
Tables\Filters\SelectFilter::make('period')->options(Subscription::PERIODS),
|
||||
])
|
||||
->actions([
|
||||
Actions\Action::make('mark_paid')
|
||||
->label('Marchează plătit')
|
||||
->icon('heroicon-m-check-circle')
|
||||
->color('success')
|
||||
->visible(fn ($r) => $r->status !== 'paid')
|
||||
->requiresConfirmation()
|
||||
->action(function (Subscription $r) {
|
||||
$r->update(['status' => 'paid', 'paid_at' => now()]);
|
||||
// Auto-extend company subscription
|
||||
$r->company->update([
|
||||
'status' => 'active',
|
||||
'active_until' => $r->period_end,
|
||||
]);
|
||||
Notification::make()->title('Plată confirmată. Abonament extins până la ' . $r->period_end->format('d.m.Y'))->success()->send();
|
||||
}),
|
||||
Actions\EditAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
])
|
||||
->emptyStateHeading('Nicio factură generată')
|
||||
->emptyStateDescription('Crează manual prima factură sau folosește butonul „Generează factură" din pagina Companiei.')
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSubscriptions::route('/'),
|
||||
'create' => Pages\CreateSubscription::route('/create'),
|
||||
'edit' => Pages\EditSubscription::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources\SubscriptionResource\Pages;
|
||||
|
||||
use App\Filament\Central\Resources\SubscriptionResource;
|
||||
use App\Models\Central\Subscription;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateSubscription extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SubscriptionResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
if (empty($data['invoice_number'])) {
|
||||
$data['invoice_number'] = Subscription::generateInvoiceNumber();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources\SubscriptionResource\Pages;
|
||||
|
||||
use App\Filament\Central\Resources\SubscriptionResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSubscription extends EditRecord
|
||||
{
|
||||
protected static string $resource = SubscriptionResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\DeleteAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources\SubscriptionResource\Pages;
|
||||
|
||||
use App\Filament\Central\Resources\SubscriptionResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSubscriptions extends ListRecords
|
||||
{
|
||||
protected static string $resource = SubscriptionResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\CreateAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources;
|
||||
|
||||
use App\Filament\Central\Resources\SuperAdminResource\Pages;
|
||||
use App\Models\Central\SuperAdmin;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class SuperAdminResource extends Resource
|
||||
{
|
||||
protected static ?string $model = SuperAdmin::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-shield-check';
|
||||
|
||||
protected static ?string $navigationLabel = 'Super-admini';
|
||||
|
||||
protected static ?string $modelLabel = 'super-admin';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'super-admini';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Acces';
|
||||
|
||||
protected static ?int $navigationSort = 50;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Schemas\Components\Section::make('Identificare')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')->required()->maxLength(120),
|
||||
Forms\Components\TextInput::make('email')->email()->required()->unique(ignoreRecord: true)->maxLength(120),
|
||||
Forms\Components\TextInput::make('phone')->tel()->maxLength(40),
|
||||
Forms\Components\Toggle::make('is_active')->label('Activ')->default(true),
|
||||
]),
|
||||
Schemas\Components\Section::make('Permisiuni')
|
||||
->columns(1)
|
||||
->schema([
|
||||
Forms\Components\Select::make('role')
|
||||
->options(SuperAdmin::ROLES)
|
||||
->default('support')
|
||||
->required()
|
||||
->helperText('Owner = drepturi totale. Admin = aproape la fel. Sales = doar tenanți + planuri. Finance = facturi. Support = read-only.'),
|
||||
]),
|
||||
Schemas\Components\Section::make('Parolă')
|
||||
->columns(1)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('password')
|
||||
->password()
|
||||
->revealable()
|
||||
->dehydrated(fn ($state) => filled($state))
|
||||
->dehydrateStateUsing(fn ($state) => Hash::make($state))
|
||||
->required(fn (string $operation) => $operation === 'create')
|
||||
->minLength(8)
|
||||
->helperText(fn (string $operation) => $operation === 'edit' ? 'Lasă gol ca să o păstrezi.' : 'Min 8 caractere.'),
|
||||
]),
|
||||
Forms\Components\Textarea::make('notes')->label('Note interne')->rows(2)->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')->searchable()->sortable()->weight('bold'),
|
||||
Tables\Columns\TextColumn::make('email')->searchable()->copyable(),
|
||||
Tables\Columns\TextColumn::make('role')
|
||||
->badge()
|
||||
->formatStateUsing(fn ($s) => array_keys(SuperAdmin::ROLES, SuperAdmin::ROLES[$s] ?? $s)[0] ?? $s)
|
||||
->color(fn ($s) => match ($s) {
|
||||
'owner' => 'danger',
|
||||
'admin' => 'warning',
|
||||
'finance' => 'success',
|
||||
'sales' => 'info',
|
||||
default => 'gray',
|
||||
}),
|
||||
Tables\Columns\IconColumn::make('is_active')->boolean()->label('Activ'),
|
||||
Tables\Columns\IconColumn::make('app_authentication_secret')
|
||||
->label('2FA')
|
||||
->boolean()
|
||||
->getStateUsing(fn ($r) => $r->app_authentication_secret !== null)
|
||||
->trueIcon('heroicon-o-lock-closed')
|
||||
->falseIcon('heroicon-o-lock-open')
|
||||
->trueColor('success')
|
||||
->falseColor('warning'),
|
||||
Tables\Columns\TextColumn::make('last_login_at')->label('Ultim login')->dateTime()->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('created_at')->date(),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('role')->options(SuperAdmin::ROLES),
|
||||
Tables\Filters\TernaryFilter::make('is_active')->label('Activ'),
|
||||
])
|
||||
->actions([
|
||||
Actions\Action::make('reset_password')
|
||||
->label('Reset parolă')
|
||||
->icon('heroicon-m-key')
|
||||
->color('warning')
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('new_password')
|
||||
->password()->required()->minLength(8)->revealable(),
|
||||
])
|
||||
->action(function (SuperAdmin $r, array $data) {
|
||||
$r->update(['password' => Hash::make($data['new_password'])]);
|
||||
Notification::make()->title('Parolă resetată.')->success()->send();
|
||||
}),
|
||||
Actions\Action::make('toggle_2fa')
|
||||
->label(fn ($r) => $r->app_authentication_secret ? 'Dezactivează 2FA' : 'Forțează re-setare 2FA')
|
||||
->icon('heroicon-m-lock-open')
|
||||
->color('danger')
|
||||
->visible(fn ($r) => $r->app_authentication_secret !== null)
|
||||
->requiresConfirmation()
|
||||
->action(function (SuperAdmin $r) {
|
||||
$r->forceFill([
|
||||
'app_authentication_secret' => null,
|
||||
'app_authentication_recovery_codes' => null,
|
||||
'email_authentication_at' => null,
|
||||
])->saveQuietly();
|
||||
Notification::make()->title('2FA dezactivat.')->success()->send();
|
||||
}),
|
||||
Actions\EditAction::make(),
|
||||
Actions\DeleteAction::make()
|
||||
->before(function (SuperAdmin $r) {
|
||||
if (auth('central')->id() === $r->id) {
|
||||
Notification::make()->title('Nu te poți șterge pe tine!')->danger()->send();
|
||||
return false;
|
||||
}
|
||||
}),
|
||||
])
|
||||
->emptyStateHeading('Doar tu ești aici')
|
||||
->emptyStateDescription('Adaugă echipa ta — colegi de la suport, sales, finance — fiecare cu rolul lui.')
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSuperAdmins::route('/'),
|
||||
'create' => Pages\CreateSuperAdmin::route('/create'),
|
||||
'edit' => Pages\EditSuperAdmin::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources\SuperAdminResource\Pages;
|
||||
|
||||
use App\Filament\Central\Resources\SuperAdminResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateSuperAdmin extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SuperAdminResource::class;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources\SuperAdminResource\Pages;
|
||||
|
||||
use App\Filament\Central\Resources\SuperAdminResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSuperAdmin extends EditRecord
|
||||
{
|
||||
protected static string $resource = SuperAdminResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\DeleteAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Resources\SuperAdminResource\Pages;
|
||||
|
||||
use App\Filament\Central\Resources\SuperAdminResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSuperAdmins extends ListRecords
|
||||
{
|
||||
protected static string $resource = SuperAdminResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\CreateAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Widgets;
|
||||
|
||||
use App\Filament\Central\Resources\SubscriptionResource;
|
||||
use App\Models\Central\Subscription;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
|
||||
class PendingPayments extends BaseWidget
|
||||
{
|
||||
protected static ?int $sort = 4;
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->heading('Facturi pending / overdue')
|
||||
->query(
|
||||
Subscription::query()
|
||||
->whereIn('status', ['pending', 'overdue'])
|
||||
->with(['company', 'plan'])
|
||||
->latest('due_at')
|
||||
->limit(10)
|
||||
)
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('invoice_number')
|
||||
->label('Factură')
|
||||
->copyable()
|
||||
->url(fn ($r) => SubscriptionResource::getUrl('edit', ['record' => $r])),
|
||||
Tables\Columns\TextColumn::make('company.name')->label('Companie'),
|
||||
Tables\Columns\TextColumn::make('plan.name')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('amount')->money(fn ($r) => $r->currency)->weight('bold'),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->color(fn ($s) => $s === 'overdue' ? 'danger' : 'warning')
|
||||
->formatStateUsing(fn ($s) => Subscription::STATUSES[$s] ?? $s),
|
||||
Tables\Columns\TextColumn::make('due_at')
|
||||
->label('Scadent')
|
||||
->dateTime()
|
||||
->color(fn ($r) => $r->due_at && $r->due_at->isPast() ? 'danger' : null),
|
||||
])
|
||||
->emptyStateHeading('🎉 Toate facturile sunt plătite')
|
||||
->paginated(false);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Central\Widgets;
|
||||
|
||||
use App\Models\Central\Company;
|
||||
use App\Models\Central\Subscription;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
@@ -20,20 +21,44 @@ class PlatformStats extends BaseWidget
|
||||
->whereDate('active_until', '<=', now()->addDays(7))
|
||||
->count();
|
||||
|
||||
$mrr = (float) Subscription::where('status', 'paid')
|
||||
->whereYear('paid_at', date('Y'))
|
||||
->whereMonth('paid_at', date('m'))
|
||||
->sum('amount');
|
||||
|
||||
$overdue = Subscription::where('status', 'overdue')->count()
|
||||
+ Subscription::where('status', 'pending')
|
||||
->whereNotNull('due_at')
|
||||
->where('due_at', '<', now())
|
||||
->count();
|
||||
|
||||
return [
|
||||
Stat::make('Companii total', $total)
|
||||
->icon('heroicon-o-building-office-2')
|
||||
->color('primary'),
|
||||
Stat::make('Tenants total', $total)
|
||||
->description('Toate companiile')
|
||||
->descriptionIcon('heroicon-m-building-office-2')
|
||||
->color('primary')
|
||||
->url(\App\Filament\Central\Resources\CompanyResource::getUrl('index')),
|
||||
Stat::make('Active', $active)
|
||||
->icon('heroicon-o-check-circle')
|
||||
->description("✓ Pe abonament plătit")
|
||||
->descriptionIcon('heroicon-m-check-circle')
|
||||
->color('success'),
|
||||
Stat::make('Trial', $trial)
|
||||
->icon('heroicon-o-clock')
|
||||
Stat::make('În trial', $trial)
|
||||
->description($trial > 0 ? 'Posibili clienți noi' : '—')
|
||||
->descriptionIcon('heroicon-m-clock')
|
||||
->color('warning'),
|
||||
Stat::make('Expiră în 7 zile', $expiring)
|
||||
->description($expiring > 0 ? 'Atenție!' : 'Toate ok')
|
||||
->icon('heroicon-o-exclamation-triangle')
|
||||
Stat::make('Expiră < 7 zile', $expiring)
|
||||
->description($expiring > 0 ? '⚠ Acțiune necesară' : 'Toate ok')
|
||||
->descriptionIcon('heroicon-m-exclamation-triangle')
|
||||
->color($expiring > 0 ? 'danger' : 'success'),
|
||||
Stat::make('Venit luna curentă', number_format($mrr, 0, ',', ' ') . ' MDL')
|
||||
->description('MRR realizat')
|
||||
->descriptionIcon('heroicon-m-banknotes')
|
||||
->color('success'),
|
||||
Stat::make('Facturi neplătite', $overdue)
|
||||
->description($overdue > 0 ? 'Verifică și amintește' : 'Toate plătite')
|
||||
->descriptionIcon('heroicon-m-exclamation-circle')
|
||||
->color($overdue > 0 ? 'danger' : 'gray')
|
||||
->url(\App\Filament\Central\Resources\SubscriptionResource::getUrl('index') . '?activeTab=overdue'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Widgets;
|
||||
|
||||
use App\Filament\Central\Resources\CompanyResource;
|
||||
use App\Models\Central\Company;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
|
||||
class RecentTenants extends BaseWidget
|
||||
{
|
||||
protected static ?int $sort = 3;
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->heading('Tenants recenți')
|
||||
->query(Company::query()->latest()->limit(8))
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('slug')
|
||||
->copyable()
|
||||
->url(fn (Company $r) => CompanyResource::getUrl('view', ['record' => $r])),
|
||||
Tables\Columns\TextColumn::make('name')->weight('bold'),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->color(fn ($s) => match ($s) {
|
||||
'active' => 'success',
|
||||
'trial' => 'warning',
|
||||
'suspended', 'expired' => 'danger',
|
||||
default => 'gray',
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('plan.name')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('users_count')->counts('users')->label('Useri'),
|
||||
Tables\Columns\TextColumn::make('created_at')->label('Creat')->since(),
|
||||
])
|
||||
->paginated(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Central\Widgets;
|
||||
|
||||
use App\Models\Central\Subscription;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
|
||||
class RevenueChart extends ChartWidget
|
||||
{
|
||||
protected ?string $heading = 'Venit lunar (MRR)';
|
||||
|
||||
protected static ?int $sort = 2;
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$months = collect(range(11, 0))->map(fn ($n) => now()->subMonths($n));
|
||||
|
||||
$values = $months->map(function ($m) {
|
||||
return (float) Subscription::where('status', 'paid')
|
||||
->whereYear('paid_at', $m->year)
|
||||
->whereMonth('paid_at', $m->month)
|
||||
->sum('amount');
|
||||
});
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'MRR (MDL)',
|
||||
'data' => $values->toArray(),
|
||||
'backgroundColor' => 'rgba(34, 197, 94, 0.15)',
|
||||
'borderColor' => '#22c55e',
|
||||
'tension' => 0.35,
|
||||
'fill' => true,
|
||||
],
|
||||
],
|
||||
'labels' => $months->map(fn ($m) => $m->format('M Y'))->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,16 @@ class Company extends BaseTenant implements HasMedia
|
||||
return $this->hasMany(User::class);
|
||||
}
|
||||
|
||||
public function subscriptions()
|
||||
{
|
||||
return $this->hasMany(Subscription::class);
|
||||
}
|
||||
|
||||
public function latestSubscription()
|
||||
{
|
||||
return $this->hasOne(Subscription::class)->latestOfMany('period_end');
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return in_array($this->status, ['active', 'trial'], true);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Central;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Subscription extends Model
|
||||
{
|
||||
public const STATUSES = [
|
||||
'pending' => 'În așteptare',
|
||||
'paid' => 'Plătit',
|
||||
'overdue' => 'Depășit termen',
|
||||
'cancelled' => 'Anulat',
|
||||
'refunded' => 'Refundat',
|
||||
];
|
||||
|
||||
public const PERIODS = [
|
||||
'monthly' => 'Lunar',
|
||||
'yearly' => 'Anual',
|
||||
];
|
||||
|
||||
public const PAYMENT_METHODS = [
|
||||
'card' => 'Card',
|
||||
'bank_transfer' => 'Transfer bancar',
|
||||
'cash' => 'Numerar',
|
||||
'other' => 'Altă metodă',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'company_id', 'plan_id',
|
||||
'period', 'amount', 'currency', 'status',
|
||||
'period_start', 'period_end', 'paid_at', 'due_at',
|
||||
'invoice_number', 'payment_method', 'reference', 'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'amount' => 'decimal:2',
|
||||
'period_start' => 'date',
|
||||
'period_end' => 'date',
|
||||
'paid_at' => 'datetime',
|
||||
'due_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function company(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function plan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Plan::class);
|
||||
}
|
||||
|
||||
public static function generateInvoiceNumber(): string
|
||||
{
|
||||
return sprintf('INV-%s-%04d',
|
||||
date('Ym'),
|
||||
(static::whereYear('created_at', date('Y'))
|
||||
->whereMonth('created_at', date('m'))
|
||||
->count()) + 1
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,16 @@ class SuperAdmin extends Authenticatable implements FilamentUser, HasAppAuthenti
|
||||
|
||||
protected $table = 'super_admins';
|
||||
|
||||
public const ROLES = [
|
||||
'owner' => 'Proprietar (toate drepturile)',
|
||||
'admin' => 'Administrator',
|
||||
'support' => 'Suport (read-only + acces tenanți)',
|
||||
'sales' => 'Vânzări (gestiune Companii + Plans)',
|
||||
'finance' => 'Financiar (Subscriptions + facturi)',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password', 'is_active', 'last_login_at',
|
||||
'name', 'email', 'phone', 'password', 'is_active', 'role', 'notes', 'last_login_at',
|
||||
'email_authentication_at',
|
||||
'app_authentication_secret', 'app_authentication_recovery_codes',
|
||||
];
|
||||
@@ -47,6 +55,11 @@ class SuperAdmin extends Authenticatable implements FilamentUser, HasAppAuthenti
|
||||
return $panel->getId() === 'central' && $this->is_active;
|
||||
}
|
||||
|
||||
public function isOwner(): bool { return $this->role === 'owner'; }
|
||||
public function isAdmin(): bool { return in_array($this->role, ['owner', 'admin'], true); }
|
||||
public function canManageBilling(): bool { return in_array($this->role, ['owner', 'admin', 'finance'], true); }
|
||||
public function canManageTenants(): bool { return in_array($this->role, ['owner', 'admin', 'sales'], true); }
|
||||
|
||||
public function hasEmailAuthentication(): bool
|
||||
{
|
||||
return $this->email_authentication_at !== null;
|
||||
|
||||
@@ -10,11 +10,13 @@ use Filament\Pages\Dashboard;
|
||||
use Filament\Panel;
|
||||
use Filament\PanelProvider;
|
||||
use Filament\Support\Colors\Color;
|
||||
use Filament\View\PanelsRenderHook;
|
||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
|
||||
/**
|
||||
@@ -50,7 +52,28 @@ class CentralPanelProvider extends PanelProvider
|
||||
->discoverWidgets(in: app_path('Filament/Central/Widgets'), for: 'App\\Filament\\Central\\Widgets')
|
||||
->widgets([
|
||||
\App\Filament\Central\Widgets\PlatformStats::class,
|
||||
\App\Filament\Central\Widgets\RevenueChart::class,
|
||||
\App\Filament\Central\Widgets\PendingPayments::class,
|
||||
\App\Filament\Central\Widgets\RecentTenants::class,
|
||||
])
|
||||
->databaseNotifications()
|
||||
->databaseNotificationsPolling('60s')
|
||||
->globalSearchKeyBindings(['command+k', 'ctrl+k'])
|
||||
->navigationGroups([
|
||||
'Tenants',
|
||||
'Acces',
|
||||
])
|
||||
->renderHook(
|
||||
PanelsRenderHook::HEAD_END,
|
||||
fn (): string => Blade::render(<<<'BLADE'
|
||||
<link rel="manifest" href="/admin-manifest.json">
|
||||
<meta name="theme-color" content="#6366f1">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
||||
<meta name="apple-mobile-web-app-title" content="AutoCRM Admin">
|
||||
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><rect width='100' height='100' rx='20' fill='%236366f1'/><text x='50' y='66' font-size='52' text-anchor='middle' fill='%23fff' font-family='sans-serif' font-weight='bold'>A</text></svg>">
|
||||
BLADE)
|
||||
)
|
||||
->middleware([
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
|
||||
Reference in New Issue
Block a user