Files
autocrm/app/Filament/Tenant/Resources/PayrollRunResource.php
T
Vasyka 06696727dd Faza 6: Activity log + Kanban + Payroll + cleanup
══════ Activity log (Spatie) ══════
- spatie/laravel-activitylog v5 instalat
- Migration cu company_id pentru tenant scoping
- Trait Auditable (App\Models\Concerns\Auditable):
  - LogOptions cu logFillable + logOnlyDirty + dontSubmitEmptyLogs
  - tapActivity auto-fill company_id + causer
  - Descrieri RO (creat/modificat/șters/restaurat)
- Aplicat pe: Client, Vehicle, Lead, Deal, WorkOrder, Payment, Expense
- ActivityResource (group Admin → Jurnal activitate)
  - Listă read-only, scope pe tenant, filtre by description/today

══════ Kanban Work Orders ══════
- Custom Filament page la /app/kanban (group Service)
- 6 coloane (new → diagnosis → agreement → in_work → awaiting_parts → ready)
- Drag-drop nativ HTML5 cu wire:click moveCard()
- Cards arată: număr fișă, client, auto, plate, master, total
- Link 'Deschide' direct la editare WO

══════ Payroll (Salarii) ══════
Schema:
- employee_profiles: user_id, position, base_salary, works_pct, parts_pct
- payroll_runs: period (YYYY-MM), base, works_revenue/pct, parts_margin/pct,
  bonus, fines, advance, total auto-calculat
- payroll_adjustments: bonus/fine/advance per period

PayrollCalculator service:
- compute($userId, $period) — calculează auto:
  - Manopere finalizate de mecanic în luna respectivă (sum total)
  - Marja pieselor montate de el (sell-buy * qty)
  - Bonus + fines + advance from adjustments
  - Total = base + works% + parts% + bonus - fines - advance

Resources Filament (group Finanțe):
- EmployeeProfileResource: profil cu % comisioane
- PayrollRunResource: salarii cu action 'Calculează luna curentă' (toți userii)
  + per-row 'Recalculează'; Sum summary pe total
- PayrollAdjustmentResource: gestionare bonus/penalizări/avansuri

══════ Cleanup ══════
- Șterse toate /__debug, /__seed, /__try-login, /__force-login, /__whoami,
  /__coolify-check (security)
- Routes/web.php conține doar / redirect, /manifest.json, /sw.js

Total Filament tenant routes: 92.
2026-05-07 09:52:01 +00:00

133 lines
6.1 KiB
PHP

<?php
namespace App\Filament\Tenant\Resources;
use App\Filament\Tenant\Resources\PayrollRunResource\Pages;
use App\Models\Tenant\PayrollRun;
use App\Models\Tenant\User;
use App\Services\PayrollCalculator;
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 PayrollRunResource extends Resource
{
protected static ?string $model = PayrollRun::class;
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-banknotes';
protected static ?string $navigationLabel = 'Salarii';
protected static string|\UnitEnum|null $navigationGroup = 'Finanțe';
protected static ?string $modelLabel = 'salariu';
protected static ?string $pluralModelLabel = 'salarii';
protected static ?int $navigationSort = 53;
public static function form(Schema $schema): Schema
{
return $schema->components([
Schemas\Components\Section::make('Detalii')
->columns(2)
->schema([
Forms\Components\Select::make('user_id')
->label('Utilizator')
->options(fn () => User::orderBy('name')->pluck('name', 'id'))
->searchable()
->required(),
Forms\Components\TextInput::make('period')
->label('Perioada (YYYY-MM)')
->placeholder(now()->format('Y-m'))
->required()
->regex('/^\d{4}-\d{2}$/'),
]),
Schemas\Components\Section::make('Calcul')
->columns(3)
->schema([
Forms\Components\TextInput::make('base')->label('Bază')->numeric()->default(0),
Forms\Components\TextInput::make('works_revenue')->label('Venit manopere')->numeric()->disabled(),
Forms\Components\TextInput::make('works_pct_amount')->label('Comision manopere')->numeric()->disabled(),
Forms\Components\TextInput::make('parts_margin')->label('Marja piese')->numeric()->disabled(),
Forms\Components\TextInput::make('parts_pct_amount')->label('Comision piese')->numeric()->disabled(),
Forms\Components\TextInput::make('bonus')->numeric()->default(0),
Forms\Components\TextInput::make('fines')->label('Penalizări')->numeric()->default(0),
Forms\Components\TextInput::make('advance')->label('Avans')->numeric()->default(0),
Forms\Components\TextInput::make('total')->label('Total net')->numeric()->disabled(),
]),
Schemas\Components\Section::make('Plată')
->columns(2)
->schema([
Forms\Components\Toggle::make('paid')->label('Achitat'),
Forms\Components\DatePicker::make('paid_at')->label('Data plății'),
]),
Forms\Components\Textarea::make('notes')->label('Notițe')->columnSpanFull()->rows(2),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('period')->label('Perioadă')->sortable(),
Tables\Columns\TextColumn::make('user.name')->label('Utilizator')->searchable(),
Tables\Columns\TextColumn::make('base')->money('MDL')->alignRight(),
Tables\Columns\TextColumn::make('works_pct_amount')->label('% manopere')->money('MDL')->alignRight(),
Tables\Columns\TextColumn::make('parts_pct_amount')->label('% piese')->money('MDL')->alignRight(),
Tables\Columns\TextColumn::make('bonus')->money('MDL')->alignRight()->color('success'),
Tables\Columns\TextColumn::make('fines')->money('MDL')->alignRight()->color('danger'),
Tables\Columns\TextColumn::make('advance')->money('MDL')->alignRight()->color('warning'),
Tables\Columns\TextColumn::make('total')->label('Total')->money('MDL')->alignRight()->weight('bold')
->summarize(Tables\Columns\Summarizers\Sum::make()->money('MDL')),
Tables\Columns\IconColumn::make('paid')->boolean(),
])
->headerActions([
Actions\Action::make('compute_all')
->label('Calculează luna curentă')
->icon('heroicon-m-calculator')
->color('primary')
->action(function () {
$period = now()->format('Y-m');
$count = 0;
foreach (User::pluck('id') as $uid) {
app(PayrollCalculator::class)->compute($uid, $period);
$count++;
}
Notification::make()
->title("Calculat salariul {$period} pentru {$count} utilizatori")
->success()->send();
}),
])
->filters([
Tables\Filters\SelectFilter::make('period')
->label('Perioadă')
->options(fn () => PayrollRun::distinct()->pluck('period', 'period')->toArray()),
Tables\Filters\TernaryFilter::make('paid')->label('Achitat'),
])
->actions([
Actions\Action::make('recompute')
->label('Recalculează')
->icon('heroicon-m-arrow-path')
->action(fn (PayrollRun $r) => app(PayrollCalculator::class)->compute($r->user_id, $r->period)),
Actions\EditAction::make(),
Actions\DeleteAction::make(),
])
->defaultSort('period', 'desc');
}
public static function getPages(): array
{
return [
'index' => Pages\ListPayrollRuns::route('/'),
'create' => Pages\CreatePayrollRun::route('/create'),
'edit' => Pages\EditPayrollRun::route('/{record}/edit'),
];
}
}