Faza 3.1: CRM core — Leads, Deals, Appointments, Settings, Widgets, Users

Spatie Permission cu teams (team_foreign_key=company_id, teams=true):
- migrations create_permission_tables (model_has_roles cu company_id scope)
- HasRoles trait pe User
- ResolveTenant middleware setează permissions team_id la tenant.id
- Seed: 7 roluri default per tenant (admin/manager/receptionist/mechanic/parts_manager/accountant/marketer)

Module noi:
- Leads (cereri): name, phone, car/model, source, UTM, status, budget, assigned_to,
  acțiune "Convertește" → creează automat Client + Deal
- Deals (pipeline): client/vehicle, stage (8 stage-uri), price, source, lost_reason
- Posts + Appointments: post_id (boxă), master_id, date+time_start+time_end, status, color
- UserResource (tenant): CRUD users cu role/status/locale; canViewAny doar pentru admin

Custom Filament page "Setări" (tenant):
- Brand & contact (display_name, city, phone, email)
- Localizare (limba RO/RU/EN, currency, theme color picker)
- Servicii & tarif (labor_rate)
- Liste configurabile (services, cars) — păstrate în companies.settings JSON

Widgets dashboard:
- Tenant: StatsOverview (Clienți, Mașini, Cereri noi, Deal-uri active, Programări azi)
- Central: PlatformStats (Companii total/active/trial, Expiră în 7 zile)

Seed extins demo PSauto:
- 3 posturi (Pod 1/2/3 cu culori)
- 2 lead-uri demo (Alex Grosu Telegram, Irina Cojocaru WhatsApp)
- 3 deal-uri demo (BMW done, Audi in_work, Porsche agree)
- 2 programări (azi + mâine)

Filament v5 fixes:
- $navigationGroup type → string|UnitEnum|null (parent stricter signature)
- Toate resources noi au tipurile corecte
This commit is contained in:
2026-05-06 17:36:32 +00:00
parent 4b1635d045
commit c9cb3560ef
34 changed files with 1742 additions and 3 deletions
@@ -0,0 +1,123 @@
<?php
namespace App\Filament\Tenant\Resources;
use App\Filament\Tenant\Resources\UserResource\Pages;
use App\Models\Tenant\User;
use Filament\Forms;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Hash;
class UserResource extends Resource
{
protected static ?string $model = User::class;
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-user-group';
protected static ?string $navigationLabel = 'Utilizatori';
protected static string|\UnitEnum|null $navigationGroup = 'Admin';
protected static ?string $modelLabel = 'utilizator';
protected static ?string $pluralModelLabel = 'utilizatori';
protected static ?int $navigationSort = 80;
public static function canViewAny(): bool
{
$u = auth()->user();
return $u && $u->role === 'admin';
}
public static function form(Schema $schema): Schema
{
return $schema->components([
Forms\Components\Section::make('Identitate')
->columns(2)
->schema([
Forms\Components\TextInput::make('name')->label('Nume')->required()->maxLength(120),
Forms\Components\TextInput::make('email')->email()->required()->maxLength(120),
Forms\Components\TextInput::make('phone')->tel()->maxLength(40),
Forms\Components\Select::make('locale')
->options(['ro' => 'Română', 'ru' => 'Русский', 'en' => 'English'])
->default('ro'),
]),
Forms\Components\Section::make('Acces')
->columns(2)
->schema([
Forms\Components\Select::make('role')
->label('Rol primar')
->options([
'admin' => 'Administrator',
'manager' => 'Manager',
'receptionist' => 'Recepție',
'mechanic' => 'Mecanic',
'parts_manager' => 'Magazioner piese',
'accountant' => 'Contabil',
'marketer' => 'Marketing',
])
->required()
->default('mechanic'),
Forms\Components\Select::make('status')
->options(['active' => 'Activ', 'inactive' => 'Inactiv', 'blocked' => 'Blocat'])
->default('active')
->required(),
Forms\Components\TextInput::make('password')
->label('Parolă')
->password()
->required(fn (string $context) => $context === 'create')
->dehydrated(fn ($state) => filled($state))
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->minLength(6)
->helperText('La editare lasă gol pentru a păstra parola actuală.'),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')->searchable()->sortable(),
Tables\Columns\TextColumn::make('email')->searchable()->copyable(),
Tables\Columns\TextColumn::make('phone')->placeholder('—'),
Tables\Columns\TextColumn::make('role')->badge(),
Tables\Columns\TextColumn::make('status')
->badge()
->colors([
'success' => ['active'],
'warning' => ['inactive'],
'danger' => ['blocked'],
]),
Tables\Columns\TextColumn::make('last_login_at')->dateTime()->placeholder('—')->toggleable(),
Tables\Columns\TextColumn::make('created_at')->date()->sortable()->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\SelectFilter::make('role')->options([
'admin' => 'Admin', 'manager' => 'Manager', 'receptionist' => 'Recepție',
'mechanic' => 'Mecanic', 'parts_manager' => 'Magazie', 'accountant' => 'Contabil', 'marketer' => 'Marketing',
]),
Tables\Filters\SelectFilter::make('status')->options([
'active' => 'Activ', 'inactive' => 'Inactiv', 'blocked' => 'Blocat',
]),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->defaultSort('created_at', 'desc');
}
public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
}