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:
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources;
|
||||
|
||||
use App\Filament\Tenant\Resources\LeadResource\Pages;
|
||||
use App\Models\Tenant\Lead;
|
||||
use App\Models\Tenant\User;
|
||||
use Filament\Forms;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class LeadResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Lead::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-inbox-arrow-down';
|
||||
|
||||
protected static ?string $navigationLabel = 'Cereri';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'CRM';
|
||||
|
||||
protected static ?string $modelLabel = 'cerere';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'cereri';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Forms\Components\Section::make('Contact')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')->label('Nume')->required()->maxLength(120),
|
||||
Forms\Components\TextInput::make('phone')->label('Telefon')->tel()->required()->maxLength(40),
|
||||
Forms\Components\TextInput::make('email')->email()->maxLength(120),
|
||||
Forms\Components\Select::make('status')
|
||||
->options(Lead::STATUSES)
|
||||
->default('new')
|
||||
->required(),
|
||||
]),
|
||||
Forms\Components\Section::make('Auto')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('car')->label('Marca')->maxLength(60),
|
||||
Forms\Components\TextInput::make('model')->maxLength(60),
|
||||
]),
|
||||
Forms\Components\Textarea::make('message')->label('Mesaj client')->columnSpanFull()->rows(3),
|
||||
Forms\Components\Section::make('Sursă & Atribuire')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\Select::make('source')
|
||||
->options(Lead::SOURCES)
|
||||
->searchable()
|
||||
->default('manual'),
|
||||
Forms\Components\Select::make('assigned_to')
|
||||
->label('Responsabil')
|
||||
->options(fn () => User::pluck('name', 'id'))
|
||||
->searchable(),
|
||||
Forms\Components\TextInput::make('budget')->label('Buget')->numeric(),
|
||||
]),
|
||||
Forms\Components\Section::make('Marketing (UTM)')
|
||||
->collapsed()
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('utm_source'),
|
||||
Forms\Components\TextInput::make('utm_medium'),
|
||||
Forms\Components\TextInput::make('utm_campaign'),
|
||||
Forms\Components\TextInput::make('utm_term'),
|
||||
Forms\Components\TextInput::make('utm_content'),
|
||||
]),
|
||||
Forms\Components\Textarea::make('notes')->label('Notițe interne')->columnSpanFull()->rows(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('created_at')->label('Data')->dateTime('d.m.Y H:i')->sortable(),
|
||||
Tables\Columns\TextColumn::make('name')->searchable()->sortable(),
|
||||
Tables\Columns\TextColumn::make('phone')->copyable()->searchable(),
|
||||
Tables\Columns\TextColumn::make('car')->label('Auto')->formatStateUsing(fn ($state, $record) => trim($state . ' ' . ($record->model ?? ''))),
|
||||
Tables\Columns\TextColumn::make('source')->label('Sursă')->formatStateUsing(fn ($state) => Lead::SOURCES[$state] ?? $state)->badge(),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->formatStateUsing(fn ($state) => Lead::STATUSES[$state] ?? $state)
|
||||
->badge()
|
||||
->colors([
|
||||
'gray' => ['new'],
|
||||
'warning' => ['contacted', 'no_answer'],
|
||||
'info' => ['scheduled'],
|
||||
'success' => ['converted'],
|
||||
'danger' => ['lost'],
|
||||
]),
|
||||
Tables\Columns\TextColumn::make('assignedTo.name')->label('Responsabil')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('budget')->money('MDL')->placeholder('—'),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('status')->options(Lead::STATUSES),
|
||||
Tables\Filters\SelectFilter::make('source')->options(Lead::SOURCES),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\Action::make('convert')
|
||||
->label('Convertește')
|
||||
->icon('heroicon-m-arrow-right-circle')
|
||||
->color('success')
|
||||
->visible(fn (Lead $r) => $r->status !== 'converted')
|
||||
->requiresConfirmation()
|
||||
->action(function (Lead $r) {
|
||||
$deal = $r->convert();
|
||||
Notification::make()
|
||||
->title('Convertit în deal #' . $deal->id)
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListLeads::route('/'),
|
||||
'create' => Pages\CreateLead::route('/create'),
|
||||
'edit' => Pages\EditLead::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user