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 ?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
|
public static function form(Schema $schema): Schema
|
||||||
{
|
{
|
||||||
return $schema->components([
|
return $schema->components([
|
||||||
@@ -123,7 +132,16 @@ class CompanyResource extends Resource
|
|||||||
'suspended' => 'Suspendat', 'archived' => 'Arhivat',
|
'suspended' => 'Suspendat', 'archived' => 'Arhivat',
|
||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
|
->recordUrl(fn (Company $r) => CompanyResource::getUrl('view', ['record' => $r]))
|
||||||
->actions([
|
->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')
|
Actions\Action::make('suspend')
|
||||||
->label('Suspendă')
|
->label('Suspendă')
|
||||||
->icon('heroicon-m-no-symbol')
|
->icon('heroicon-m-no-symbol')
|
||||||
@@ -141,6 +159,9 @@ class CompanyResource extends Resource
|
|||||||
Actions\EditAction::make(),
|
Actions\EditAction::make(),
|
||||||
Actions\DeleteAction::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');
|
->defaultSort('created_at', 'desc');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +170,7 @@ class CompanyResource extends Resource
|
|||||||
return [
|
return [
|
||||||
'index' => Pages\ListCompanies::route('/'),
|
'index' => Pages\ListCompanies::route('/'),
|
||||||
'create' => Pages\CreateCompany::route('/create'),
|
'create' => Pages\CreateCompany::route('/create'),
|
||||||
|
'view' => Pages\ViewCompany::route('/{record}'),
|
||||||
'edit' => Pages\EditCompany::route('/{record}/edit'),
|
'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;
|
namespace App\Filament\Central\Widgets;
|
||||||
|
|
||||||
use App\Models\Central\Company;
|
use App\Models\Central\Company;
|
||||||
|
use App\Models\Central\Subscription;
|
||||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||||
|
|
||||||
@@ -20,20 +21,44 @@ class PlatformStats extends BaseWidget
|
|||||||
->whereDate('active_until', '<=', now()->addDays(7))
|
->whereDate('active_until', '<=', now()->addDays(7))
|
||||||
->count();
|
->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 [
|
return [
|
||||||
Stat::make('Companii total', $total)
|
Stat::make('Tenants total', $total)
|
||||||
->icon('heroicon-o-building-office-2')
|
->description('Toate companiile')
|
||||||
->color('primary'),
|
->descriptionIcon('heroicon-m-building-office-2')
|
||||||
|
->color('primary')
|
||||||
|
->url(\App\Filament\Central\Resources\CompanyResource::getUrl('index')),
|
||||||
Stat::make('Active', $active)
|
Stat::make('Active', $active)
|
||||||
->icon('heroicon-o-check-circle')
|
->description("✓ Pe abonament plătit")
|
||||||
|
->descriptionIcon('heroicon-m-check-circle')
|
||||||
->color('success'),
|
->color('success'),
|
||||||
Stat::make('Trial', $trial)
|
Stat::make('În trial', $trial)
|
||||||
->icon('heroicon-o-clock')
|
->description($trial > 0 ? 'Posibili clienți noi' : '—')
|
||||||
|
->descriptionIcon('heroicon-m-clock')
|
||||||
->color('warning'),
|
->color('warning'),
|
||||||
Stat::make('Expiră în 7 zile', $expiring)
|
Stat::make('Expiră < 7 zile', $expiring)
|
||||||
->description($expiring > 0 ? 'Atenție!' : 'Toate ok')
|
->description($expiring > 0 ? '⚠ Acțiune necesară' : 'Toate ok')
|
||||||
->icon('heroicon-o-exclamation-triangle')
|
->descriptionIcon('heroicon-m-exclamation-triangle')
|
||||||
->color($expiring > 0 ? 'danger' : 'success'),
|
->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);
|
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
|
public function isActive(): bool
|
||||||
{
|
{
|
||||||
return in_array($this->status, ['active', 'trial'], true);
|
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';
|
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 = [
|
protected $fillable = [
|
||||||
'name', 'email', 'password', 'is_active', 'last_login_at',
|
'name', 'email', 'phone', 'password', 'is_active', 'role', 'notes', 'last_login_at',
|
||||||
'email_authentication_at',
|
'email_authentication_at',
|
||||||
'app_authentication_secret', 'app_authentication_recovery_codes',
|
'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;
|
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
|
public function hasEmailAuthentication(): bool
|
||||||
{
|
{
|
||||||
return $this->email_authentication_at !== null;
|
return $this->email_authentication_at !== null;
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ use Filament\Pages\Dashboard;
|
|||||||
use Filament\Panel;
|
use Filament\Panel;
|
||||||
use Filament\PanelProvider;
|
use Filament\PanelProvider;
|
||||||
use Filament\Support\Colors\Color;
|
use Filament\Support\Colors\Color;
|
||||||
|
use Filament\View\PanelsRenderHook;
|
||||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
use Illuminate\Cookie\Middleware\EncryptCookies;
|
||||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||||
use Illuminate\Session\Middleware\StartSession;
|
use Illuminate\Session\Middleware\StartSession;
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
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')
|
->discoverWidgets(in: app_path('Filament/Central/Widgets'), for: 'App\\Filament\\Central\\Widgets')
|
||||||
->widgets([
|
->widgets([
|
||||||
\App\Filament\Central\Widgets\PlatformStats::class,
|
\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([
|
->middleware([
|
||||||
EncryptCookies::class,
|
EncryptCookies::class,
|
||||||
AddQueuedCookiesToResponse::class,
|
AddQueuedCookiesToResponse::class,
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration {
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('subscriptions', function (Blueprint $t) {
|
||||||
|
$t->id();
|
||||||
|
$t->foreignId('company_id')->constrained()->cascadeOnDelete();
|
||||||
|
$t->foreignId('plan_id')->nullable()->constrained()->nullOnDelete();
|
||||||
|
|
||||||
|
$t->enum('period', ['monthly', 'yearly'])->default('monthly');
|
||||||
|
$t->decimal('amount', 10, 2);
|
||||||
|
$t->string('currency', 3)->default('MDL');
|
||||||
|
|
||||||
|
$t->enum('status', ['pending', 'paid', 'overdue', 'cancelled', 'refunded'])
|
||||||
|
->default('pending');
|
||||||
|
|
||||||
|
$t->date('period_start');
|
||||||
|
$t->date('period_end');
|
||||||
|
$t->timestamp('paid_at')->nullable();
|
||||||
|
$t->timestamp('due_at')->nullable();
|
||||||
|
|
||||||
|
$t->string('invoice_number', 30)->nullable();
|
||||||
|
$t->string('payment_method', 30)->nullable(); // card, bank_transfer, cash
|
||||||
|
$t->string('reference', 100)->nullable(); // Stripe id, transfer ref
|
||||||
|
$t->text('notes')->nullable();
|
||||||
|
|
||||||
|
$t->timestamps();
|
||||||
|
|
||||||
|
$t->index(['company_id', 'status']);
|
||||||
|
$t->index('due_at');
|
||||||
|
$t->index('paid_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('subscriptions');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration {
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('super_admins', function (Blueprint $t) {
|
||||||
|
$t->enum('role', ['owner', 'admin', 'support', 'sales', 'finance'])
|
||||||
|
->default('support')->after('is_active');
|
||||||
|
$t->string('phone', 40)->nullable()->after('email');
|
||||||
|
$t->text('notes')->nullable()->after('phone');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('super_admins', function (Blueprint $t) {
|
||||||
|
$t->dropColumn(['role', 'phone', 'notes']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -39,25 +39,41 @@ class DatabaseSeeder extends Seeder
|
|||||||
$free = Plan::firstOrCreate(['slug' => 'free'], [
|
$free = Plan::firstOrCreate(['slug' => 'free'], [
|
||||||
'name' => 'Free',
|
'name' => 'Free',
|
||||||
'price_monthly' => 0,
|
'price_monthly' => 0,
|
||||||
|
'price_yearly' => 0,
|
||||||
'currency' => 'MDL',
|
'currency' => 'MDL',
|
||||||
'features' => ['core'],
|
'features' => ['kanban'],
|
||||||
'limits' => ['max_users' => 2, 'max_vehicles' => 50],
|
'limits' => ['max_users' => 2, 'max_vehicles' => 50, 'max_clients' => 100, 'storage_mb' => 100],
|
||||||
|
'is_active' => true, 'is_public' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Plan::firstOrCreate(['slug' => 'basic'], [
|
Plan::firstOrCreate(['slug' => 'basic'], [
|
||||||
'name' => 'Basic',
|
'name' => 'Basic',
|
||||||
'price_monthly' => 299,
|
'price_monthly' => 299,
|
||||||
|
'price_yearly' => 2990,
|
||||||
'currency' => 'MDL',
|
'currency' => 'MDL',
|
||||||
'features' => ['core', 'workorders', 'kanban'],
|
'features' => ['kanban', 'pdf', 'reports'],
|
||||||
'limits' => ['max_users' => 5, 'max_vehicles' => 500],
|
'limits' => ['max_users' => 5, 'max_vehicles' => 500, 'max_clients' => 1000, 'storage_mb' => 1000],
|
||||||
|
'is_active' => true, 'is_public' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Plan::firstOrCreate(['slug' => 'pro'], [
|
Plan::firstOrCreate(['slug' => 'pro'], [
|
||||||
'name' => 'Pro',
|
'name' => 'Pro',
|
||||||
'price_monthly' => 599,
|
'price_monthly' => 599,
|
||||||
|
'price_yearly' => 5990,
|
||||||
'currency' => 'MDL',
|
'currency' => 'MDL',
|
||||||
'features' => ['core', 'workorders', 'kanban', 'reports', 'ai', 'api'],
|
'features' => ['kanban', 'pdf', 'reports', 'ai', 'api', 'reverb', 'multi_user', 'white_label'],
|
||||||
'limits' => ['max_users' => -1, 'max_vehicles' => -1],
|
'limits' => ['max_users' => 20, 'max_vehicles' => 5000, 'max_clients' => 10000, 'storage_mb' => 10000, 'ai_messages_month' => 1000],
|
||||||
|
'is_active' => true, 'is_public' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Plan::firstOrCreate(['slug' => 'enterprise'], [
|
||||||
|
'name' => 'Enterprise',
|
||||||
|
'price_monthly' => 1499,
|
||||||
|
'price_yearly' => 14990,
|
||||||
|
'currency' => 'MDL',
|
||||||
|
'features' => ['kanban', 'pdf', 'reports', 'ai', 'api', 'reverb', 'multi_user', 'white_label', 'priority_support', 'custom_domain'],
|
||||||
|
'limits' => [],
|
||||||
|
'is_active' => true, 'is_public' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// ─── Super-admin (operator platformă) ─────────────────────
|
// ─── Super-admin (operator platformă) ─────────────────────
|
||||||
@@ -65,8 +81,29 @@ class DatabaseSeeder extends Seeder
|
|||||||
'name' => 'Vasyka',
|
'name' => 'Vasyka',
|
||||||
'password' => Hash::make('admin123'),
|
'password' => Hash::make('admin123'),
|
||||||
'is_active' => true,
|
'is_active' => true,
|
||||||
|
'role' => 'owner',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// ─── Subscription demo (PSauto pe Pro plan, plătit) ──────
|
||||||
|
$proPlan = Plan::where('slug', 'pro')->first();
|
||||||
|
$psautoCompany = Company::where('slug', 'psauto')->first();
|
||||||
|
if ($proPlan && $psautoCompany) {
|
||||||
|
\App\Models\Central\Subscription::firstOrCreate(
|
||||||
|
['company_id' => $psautoCompany->id, 'period_start' => today()->startOfMonth()],
|
||||||
|
[
|
||||||
|
'plan_id' => $proPlan->id,
|
||||||
|
'period' => 'monthly',
|
||||||
|
'amount' => $proPlan->price_monthly,
|
||||||
|
'currency' => 'MDL',
|
||||||
|
'status' => 'paid',
|
||||||
|
'period_end' => today()->endOfMonth(),
|
||||||
|
'paid_at' => today()->startOfMonth()->addDay(),
|
||||||
|
'invoice_number' => 'INV-' . date('Ym') . '-0001',
|
||||||
|
'payment_method' => 'bank_transfer',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// ─── PSauto demo company ──────────────────────────────────
|
// ─── PSauto demo company ──────────────────────────────────
|
||||||
$psauto = Company::firstOrCreate(['slug' => 'psauto'], [
|
$psauto = Company::firstOrCreate(['slug' => 'psauto'], [
|
||||||
'name' => 'PSauto SRL',
|
'name' => 'PSauto SRL',
|
||||||
|
|||||||
@@ -0,0 +1,239 @@
|
|||||||
|
<x-filament-panels::page>
|
||||||
|
<style>
|
||||||
|
.cv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
|
||||||
|
.cv-card {
|
||||||
|
background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
|
||||||
|
padding: 16px; position: relative;
|
||||||
|
}
|
||||||
|
.dark .cv-card { background: #1f2937; border-color: #374151; }
|
||||||
|
.cv-card .label { font-size: 11px; color: #9ca3af; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
|
||||||
|
.cv-card .value { font-size: 22px; font-weight: 700; }
|
||||||
|
.cv-card .sub { font-size: 12px; color: #6b7280; margin-top: 2px; }
|
||||||
|
.cv-card.warn { border-color: #f59e0b; background: #fffbeb; }
|
||||||
|
.dark .cv-card.warn { background: #78350f30; }
|
||||||
|
.cv-card.danger { border-color: #ef4444; background: #fef2f2; }
|
||||||
|
.dark .cv-card.danger { background: #7f1d1d30; }
|
||||||
|
.cv-card.success { border-color: #10b981; background: #ecfdf5; }
|
||||||
|
.dark .cv-card.success { background: #064e3b30; }
|
||||||
|
|
||||||
|
.cv-section { margin-top: 24px; }
|
||||||
|
.cv-section-title { font-size: 14px; font-weight: 600; color: #6b7280; margin-bottom: 12px; text-transform: uppercase; letter-spacing: .5px; }
|
||||||
|
|
||||||
|
.cv-table { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; border-radius: 8px; overflow: hidden; border: 1px solid #e5e7eb; }
|
||||||
|
.dark .cv-table { background: #1f2937; border-color: #374151; }
|
||||||
|
.cv-table th, .cv-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid #f3f4f6; }
|
||||||
|
.dark .cv-table th, .dark .cv-table td { border-color: #374151; }
|
||||||
|
.cv-table th { font-size: 11px; font-weight: 600; color: #9ca3af; text-transform: uppercase; }
|
||||||
|
|
||||||
|
.cv-badge { display: inline-block; padding: 3px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
|
||||||
|
.cv-badge-success { background: #dcfce7; color: #166534; }
|
||||||
|
.cv-badge-warning { background: #fef3c7; color: #92400e; }
|
||||||
|
.cv-badge-danger { background: #fee2e2; color: #991b1b; }
|
||||||
|
.cv-badge-gray { background: #f3f4f6; color: #4b5563; }
|
||||||
|
.dark .cv-badge-success { background: #14532d; color: #86efac; }
|
||||||
|
.dark .cv-badge-warning { background: #78350f; color: #fde68a; }
|
||||||
|
.dark .cv-badge-danger { background: #7f1d1d; color: #fca5a5; }
|
||||||
|
.dark .cv-badge-gray { background: #374151; color: #d1d5db; }
|
||||||
|
|
||||||
|
.cv-header {
|
||||||
|
display: flex; gap: 16px; align-items: center;
|
||||||
|
background: linear-gradient(135deg, #eff6ff, #dbeafe);
|
||||||
|
padding: 20px; border-radius: 12px; border: 1px solid #bfdbfe;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
.dark .cv-header { background: linear-gradient(135deg, #1e3a8a40, #1e40af30); border-color: #1e3a8a; }
|
||||||
|
.cv-header img { max-height: 64px; max-width: 80px; border-radius: 8px; background: #fff; padding: 4px; }
|
||||||
|
.cv-header h2 { font-size: 22px; font-weight: 700; }
|
||||||
|
.cv-header .sub { font-size: 13px; color: #4b5563; }
|
||||||
|
.dark .cv-header .sub { color: #9ca3af; }
|
||||||
|
</style>
|
||||||
|
|
||||||
|
@php
|
||||||
|
$stats = $this->getStats();
|
||||||
|
$daysLeft = $this->getDaysUntilExpiry();
|
||||||
|
$statusColors = [
|
||||||
|
'active' => 'success',
|
||||||
|
'trial' => 'warning',
|
||||||
|
'suspended' => 'danger',
|
||||||
|
'expired' => 'danger',
|
||||||
|
'archived' => 'gray',
|
||||||
|
];
|
||||||
|
$statusLabel = match ($this->record->status) {
|
||||||
|
'active' => 'Activ',
|
||||||
|
'trial' => 'Trial',
|
||||||
|
'suspended' => 'Suspendat',
|
||||||
|
'expired' => 'Expirat',
|
||||||
|
'archived' => 'Arhivat',
|
||||||
|
default => $this->record->status,
|
||||||
|
};
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
{{-- HEADER --}}
|
||||||
|
<div class="cv-header">
|
||||||
|
@if ($this->record->getLogoUrl())
|
||||||
|
<img src="{{ $this->record->getLogoUrl() }}" alt="logo">
|
||||||
|
@endif
|
||||||
|
<div style="flex:1;">
|
||||||
|
<h2>{{ $this->record->display_name ?? $this->record->name }}</h2>
|
||||||
|
<div class="sub">
|
||||||
|
<a href="{{ $this->record->url() }}" target="_blank" style="color:inherit;text-decoration:underline;">{{ $this->record->slug }}.service.mir.md</a>
|
||||||
|
@if ($this->record->city) · {{ $this->record->city }} @endif
|
||||||
|
@if ($this->record->phone) · {{ $this->record->phone }} @endif
|
||||||
|
@if ($this->record->email) · {{ $this->record->email }} @endif
|
||||||
|
</div>
|
||||||
|
<div style="margin-top:8px;display:flex;gap:6px;align-items:center;flex-wrap:wrap;">
|
||||||
|
<span class="cv-badge cv-badge-{{ $statusColors[$this->record->status] ?? 'gray' }}">
|
||||||
|
{{ $statusLabel }}
|
||||||
|
</span>
|
||||||
|
@if ($this->record->plan)
|
||||||
|
<span class="cv-badge cv-badge-gray">📦 {{ $this->record->plan->name }}</span>
|
||||||
|
@else
|
||||||
|
<span class="cv-badge cv-badge-warning">⚠ Fără plan</span>
|
||||||
|
@endif
|
||||||
|
@if ($daysLeft !== null)
|
||||||
|
@if ($daysLeft < 0)
|
||||||
|
<span class="cv-badge cv-badge-danger">Expirat acum {{ abs($daysLeft) }} zile</span>
|
||||||
|
@elseif ($daysLeft < 7)
|
||||||
|
<span class="cv-badge cv-badge-warning">Expiră în {{ $daysLeft }} zile</span>
|
||||||
|
@else
|
||||||
|
<span class="cv-badge cv-badge-success">{{ $daysLeft }} zile rămase</span>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- STATS GRID --}}
|
||||||
|
<div class="cv-section">
|
||||||
|
<div class="cv-section-title">📊 Activitate live</div>
|
||||||
|
<div class="cv-grid">
|
||||||
|
<div class="cv-card">
|
||||||
|
<div class="label">Useri</div>
|
||||||
|
<div class="value">{{ $stats['users'] }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card">
|
||||||
|
<div class="label">Clienți</div>
|
||||||
|
<div class="value">{{ $stats['clients'] }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card">
|
||||||
|
<div class="label">Mașini</div>
|
||||||
|
<div class="value">{{ $stats['vehicles'] }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card {{ $stats['work_orders_open'] > 0 ? 'warn' : '' }}">
|
||||||
|
<div class="label">Fișe lucru</div>
|
||||||
|
<div class="value">{{ $stats['work_orders'] }}</div>
|
||||||
|
<div class="sub">{{ $stats['work_orders_open'] }} deschise</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card {{ $stats['parts_low_stock'] > 0 ? 'warn' : '' }}">
|
||||||
|
<div class="label">Piese în stoc</div>
|
||||||
|
<div class="value">{{ $stats['parts'] }}</div>
|
||||||
|
@if ($stats['parts_low_stock'])
|
||||||
|
<div class="sub">⚠ {{ $stats['parts_low_stock'] }} sub minim</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
<div class="cv-card success">
|
||||||
|
<div class="label">Venit luna curentă</div>
|
||||||
|
<div class="value">{{ number_format($stats['revenue_this_month'], 0, ',', ' ') }}</div>
|
||||||
|
<div class="sub">{{ $this->record->settings['currency'] ?? 'MDL' }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card">
|
||||||
|
<div class="label">Venit luna trecută</div>
|
||||||
|
<div class="value">{{ number_format($stats['revenue_last_month'], 0, ',', ' ') }}</div>
|
||||||
|
<div class="sub">{{ $this->record->settings['currency'] ?? 'MDL' }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card">
|
||||||
|
<div class="label">Storage media</div>
|
||||||
|
<div class="value">{{ $stats['storage_mb'] }}</div>
|
||||||
|
<div class="sub">MB folosiți</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card {{ $stats['last_login'] && \Carbon\Carbon::parse($stats['last_login'])->diffInDays() > 14 ? 'danger' : '' }}">
|
||||||
|
<div class="label">Ultima logare</div>
|
||||||
|
<div class="value" style="font-size:14px;">
|
||||||
|
{{ $stats['last_login'] ? \Carbon\Carbon::parse($stats['last_login'])->diffForHumans() : 'Niciodată' }}
|
||||||
|
</div>
|
||||||
|
@if ($stats['last_login'] && \Carbon\Carbon::parse($stats['last_login'])->diffInDays() > 14)
|
||||||
|
<div class="sub">⚠ Posibil churn</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- SUBSCRIPTIONS --}}
|
||||||
|
<div class="cv-section">
|
||||||
|
<div class="cv-section-title">💳 Istoric abonamente</div>
|
||||||
|
@if ($this->record->subscriptions->isEmpty())
|
||||||
|
<div style="padding:32px;text-align:center;color:#9ca3af;font-size:13px;border:1px dashed #e5e7eb;border-radius:8px;">
|
||||||
|
Niciun abonament emis. Folosește „Generează factură" de sus.
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
|
<table class="cv-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Factură</th>
|
||||||
|
<th>Plan</th>
|
||||||
|
<th>Perioadă</th>
|
||||||
|
<th>Sumă</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Plătit</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach ($this->record->subscriptions as $s)
|
||||||
|
<tr>
|
||||||
|
<td><b>{{ $s->invoice_number ?? '—' }}</b></td>
|
||||||
|
<td>{{ $s->plan?->name ?? '—' }}</td>
|
||||||
|
<td>{{ $s->period_start?->format('d.m.Y') }} → {{ $s->period_end?->format('d.m.Y') }}</td>
|
||||||
|
<td><b>{{ number_format($s->amount, 2) }} {{ $s->currency }}</b></td>
|
||||||
|
<td>
|
||||||
|
<span class="cv-badge cv-badge-{{ match($s->status){'paid'=>'success','overdue'=>'danger','pending'=>'warning',default=>'gray'} }}">
|
||||||
|
{{ \App\Models\Central\Subscription::STATUSES[$s->status] ?? $s->status }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>{{ $s->paid_at?->format('d.m.Y') ?? '—' }}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- CONFIG --}}
|
||||||
|
<div class="cv-section">
|
||||||
|
<div class="cv-section-title">⚙ Configurare tenant</div>
|
||||||
|
<div class="cv-grid" style="grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));">
|
||||||
|
<div class="cv-card">
|
||||||
|
<div class="label">Limbă</div>
|
||||||
|
<div class="value" style="font-size:14px;">
|
||||||
|
{{ ['ro' => 'Română', 'ru' => 'Русский', 'en' => 'English'][$this->record->settings['language'] ?? 'ro'] ?? '—' }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card">
|
||||||
|
<div class="label">Monedă</div>
|
||||||
|
<div class="value" style="font-size:14px;">{{ $this->record->settings['currency'] ?? 'MDL' }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card">
|
||||||
|
<div class="label">Tarif normo-oră</div>
|
||||||
|
<div class="value" style="font-size:14px;">{{ $this->record->settings['labor_rate'] ?? '—' }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card">
|
||||||
|
<div class="label">Onboarded</div>
|
||||||
|
<div class="value" style="font-size:14px;">
|
||||||
|
{{ ! empty($this->record->settings['onboarded_at']) ? '✓ Da' : '✗ Nu' }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card">
|
||||||
|
<div class="label">Theme color</div>
|
||||||
|
<div class="value" style="display:flex;align-items:center;gap:6px;font-size:14px;">
|
||||||
|
<span style="display:inline-block;width:18px;height:18px;border-radius:3px;background:{{ $this->record->settings['theme_color'] ?? '#3B82F6' }};"></span>
|
||||||
|
{{ $this->record->settings['theme_color'] ?? '#3B82F6' }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="cv-card">
|
||||||
|
<div class="label">AI provider</div>
|
||||||
|
<div class="value" style="font-size:14px;">
|
||||||
|
{{ $this->record->settings['ai']['default_provider'] ?? 'neconfigurat' }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</x-filament-panels::page>
|
||||||
@@ -47,6 +47,25 @@ Route::post('/locale/{lang}', function (Request $request, string $lang) {
|
|||||||
return back();
|
return back();
|
||||||
})->name('locale.switch');
|
})->name('locale.switch');
|
||||||
|
|
||||||
|
// PWA — manifest pentru panou central (service.mir.md).
|
||||||
|
Route::get('/admin-manifest.json', function () {
|
||||||
|
return response()->json([
|
||||||
|
'name' => 'AutoCRM Admin',
|
||||||
|
'short_name' => 'AutoCRM',
|
||||||
|
'description' => 'Panou administrativ AutoCRM SaaS',
|
||||||
|
'start_url' => '/admin',
|
||||||
|
'display' => 'standalone',
|
||||||
|
'orientation' => 'any',
|
||||||
|
'background_color' => '#ffffff',
|
||||||
|
'theme_color' => '#6366f1',
|
||||||
|
'lang' => 'ro',
|
||||||
|
'icons' => [
|
||||||
|
['src' => '/pwa/admin-192.png', 'sizes' => '192x192', 'type' => 'image/png'],
|
||||||
|
['src' => '/pwa/admin-512.png', 'sizes' => '512x512', 'type' => 'image/png'],
|
||||||
|
],
|
||||||
|
])->header('Cache-Control', 'public, max-age=3600');
|
||||||
|
});
|
||||||
|
|
||||||
// PWA — manifest dinamic per tenant.
|
// PWA — manifest dinamic per tenant.
|
||||||
Route::get('/manifest.json', function (Request $request) {
|
Route::get('/manifest.json', function (Request $request) {
|
||||||
$tenant = app(TenantManager::class)->current();
|
$tenant = app(TenantManager::class)->current();
|
||||||
|
|||||||
Reference in New Issue
Block a user