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
+109
View File
@@ -0,0 +1,109 @@
<?php
namespace App\Filament\Tenant\Pages;
use App\Tenancy\TenantManager;
use Filament\Forms;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Schema;
class Settings extends Page
{
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-cog-6-tooth';
protected static ?string $navigationLabel = 'Setări';
protected static string|\UnitEnum|null $navigationGroup = 'Admin';
protected static ?int $navigationSort = 90;
protected static ?string $title = 'Setări companie';
protected string $view = 'filament.tenant.pages.settings';
public ?array $data = [];
public function mount(): void
{
$company = app(TenantManager::class)->current();
$settings = (array) ($company->settings ?? []);
$this->data = [
'display_name' => $company->display_name ?? $company->name,
'city' => $company->city,
'phone' => $company->phone,
'email' => $company->email,
'currency' => $settings['currency'] ?? 'MDL',
'language' => $settings['language'] ?? 'ro',
'theme_color' => $settings['theme_color'] ?? '#3B82F6',
'labor_rate' => $settings['labor_rate'] ?? 400,
'services' => isset($settings['services']) ? implode(', ', (array) $settings['services']) : '',
'cars' => isset($settings['cars']) ? implode(', ', (array) $settings['cars']) : '',
];
}
public function form(Schema $schema): Schema
{
return $schema
->components([
Forms\Components\Section::make('Brand & contact')
->columns(2)
->schema([
Forms\Components\TextInput::make('display_name')->label('Denumire afișată')->maxLength(120),
Forms\Components\TextInput::make('city')->label('Oraș')->maxLength(60),
Forms\Components\TextInput::make('phone')->label('Telefon')->tel()->maxLength(40),
Forms\Components\TextInput::make('email')->email()->maxLength(120),
]),
Forms\Components\Section::make('Localizare & monedă')
->columns(3)
->schema([
Forms\Components\Select::make('language')
->label('Limbă default')
->options(['ro' => 'Română', 'ru' => 'Русский', 'en' => 'English'])
->required(),
Forms\Components\TextInput::make('currency')->label('Monedă')->maxLength(8)->required(),
Forms\Components\ColorPicker::make('theme_color')->label('Culoare brand'),
]),
Forms\Components\Section::make('Servicii & tarif')
->columns(2)
->schema([
Forms\Components\TextInput::make('labor_rate')->label('Tarif normo-oră')->numeric()->required(),
]),
Forms\Components\Section::make('Liste configurabile')
->columns(1)
->schema([
Forms\Components\Textarea::make('services')
->label('Servicii oferite (separate prin virgulă)')
->rows(2),
Forms\Components\Textarea::make('cars')
->label('Mărci auto suportate (separate prin virgulă)')
->rows(2),
]),
])
->statePath('data');
}
public function save(): void
{
$data = $this->form->getState();
$company = app(TenantManager::class)->current();
$company->update([
'display_name' => $data['display_name'] ?? null,
'city' => $data['city'] ?? null,
'phone' => $data['phone'] ?? null,
'email' => $data['email'] ?? null,
'settings' => array_merge((array) $company->settings, [
'language' => $data['language'] ?? 'ro',
'currency' => $data['currency'] ?? 'MDL',
'theme_color' => $data['theme_color'] ?? '#3B82F6',
'labor_rate' => (float) ($data['labor_rate'] ?? 400),
'services' => array_values(array_filter(array_map('trim', explode(',', (string) ($data['services'] ?? ''))))),
'cars' => array_values(array_filter(array_map('trim', explode(',', (string) ($data['cars'] ?? ''))))),
]),
]);
Notification::make()->title('Setări salvate')->success()->send();
}
}