Files
Vasyka 95aeecb932 i18n: fix widget heading, translate Select options from model consts, +40 keys
- LowStockTable: rename getHeading → getTableHeading (correct Filament API)
- Global I18n::opts() helper wraps Model::CONST values in __() so
  Select dropdowns show translated status/type/season/etc. labels
- Sed-transform ->options(X::CONST), ->options(array_combine(X::A,X::A)),
  and formatStateUsing(fn($s)=>X::CONST[$s]??$s) → wrap with __()
  (58 options + 10 combines + 7 formatStateUsing across 28 files)
- CalendarBoard: all 7 day names now via __() (was missing 4)
- calendar-board.blade: fix untranslated 'săptămâna curentă', 'capacitate',
  'rata confirmare', 'mediu', 'plin', 'Pod / Zi' / 'Mecanic / Zi'
- +40 RU/EN translations (Client & Auto, Maistru / Mecanic, Programat,
  Sosit, Finalizat, Anulat, Neprezentat, days of week, calendar KPIs)

All 306 tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-16 06:42:16 +00:00

168 lines
6.9 KiB
PHP

<?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\Actions;
use Filament\Schemas;
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';
public static function getNavigationLabel(): string
{
return __('nav.label.Cereri');
}
public static function getNavigationGroup(): ?string
{
return __('nav.group.CRM');
}
protected static ?string $modelLabel = null;
public static function getModelLabel(): string
{
return __('cerere');
}
protected static ?string $pluralModelLabel = null;
public static function getPluralModelLabel(): string
{
return __('cereri');
}
protected static ?int $navigationSort = 5;
public static function getGloballySearchableAttributes(): array
{
return ['name', 'phone', 'email', 'source', 'car', 'model'];
}
public static function getGlobalSearchResultDetails(\Illuminate\Database\Eloquent\Model $record): array
{
return [
'Telefon' => $record->phone,
'Status' => $record->status,
];
}
public static function form(Schema $schema): Schema
{
return $schema->components([
Schemas\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(\App\Support\I18n::opts(Lead::STATUSES))
->default('new')
->required(),
]),
Schemas\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),
Schemas\Components\Section::make(__('Sursă & Atribuire'))
->columns(2)
->schema([
Forms\Components\Select::make('source')
->options(\App\Support\I18n::opts(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(),
]),
Schemas\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(\App\Support\I18n::opts(Lead::STATUSES)),
Tables\Filters\SelectFilter::make('source')->options(\App\Support\I18n::opts(Lead::SOURCES)),
])
->actions([
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();
}),
Actions\EditAction::make(),
Actions\DeleteAction::make(),
])
->emptyStateHeading('Nicio cerere primită')
->emptyStateDescription(__('Aici apar cererile clienților potențiali. Convertește-le în deal-uri sau direct în programări de la butonul „Convertește".'))
->emptyStateIcon('heroicon-o-inbox-arrow-down')
->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'),
];
}
}