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.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Pages;
|
||||
|
||||
use App\Models\Tenant\WorkOrder;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class Kanban extends Page
|
||||
{
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-view-columns';
|
||||
|
||||
protected static ?string $navigationLabel = 'Kanban';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Service';
|
||||
|
||||
protected static ?int $navigationSort = 31;
|
||||
|
||||
protected static ?string $title = 'Kanban — Fișe de lucru';
|
||||
|
||||
protected string $view = 'filament.tenant.pages.kanban';
|
||||
|
||||
public function getColumns(): array
|
||||
{
|
||||
$statuses = ['new', 'diagnosis', 'agreement', 'in_work', 'awaiting_parts', 'ready'];
|
||||
$byStatus = WorkOrder::whereIn('status', $statuses)
|
||||
->with(['client:id,name', 'vehicle:id,plate,make,model', 'master:id,name'])
|
||||
->orderBy('opened_at')
|
||||
->get()
|
||||
->groupBy('status');
|
||||
|
||||
$columns = [];
|
||||
foreach ($statuses as $status) {
|
||||
$columns[$status] = [
|
||||
'label' => WorkOrder::STATUSES[$status] ?? $status,
|
||||
'cards' => $byStatus->get($status, collect())->all(),
|
||||
'count' => $byStatus->get($status, collect())->count(),
|
||||
];
|
||||
}
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public function moveCard(int $id, string $status): void
|
||||
{
|
||||
if (! in_array($status, array_keys(WorkOrder::STATUSES), true)) {
|
||||
return;
|
||||
}
|
||||
$wo = WorkOrder::find($id);
|
||||
if (! $wo) return;
|
||||
|
||||
$wo->update(['status' => $status]);
|
||||
|
||||
Notification::make()
|
||||
->title("Fișa #{$wo->number} → " . (WorkOrder::STATUSES[$status] ?? $status))
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources;
|
||||
|
||||
use App\Filament\Tenant\Resources\ActivityResource\Pages;
|
||||
use App\Tenancy\TenantManager;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
class ActivityResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Activity::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-list-bullet';
|
||||
|
||||
protected static ?string $navigationLabel = 'Jurnal activitate';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Admin';
|
||||
|
||||
protected static ?string $modelLabel = 'eveniment';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'jurnal';
|
||||
|
||||
protected static ?int $navigationSort = 95;
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
$tenantId = app(TenantManager::class)->currentId();
|
||||
return parent::getEloquentQuery()
|
||||
->when($tenantId, fn ($q) => $q->where('company_id', $tenantId));
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('created_at')->label('Când')->dateTime('d.m.Y H:i')->sortable(),
|
||||
Tables\Columns\TextColumn::make('description')->label('Acțiune')->badge()
|
||||
->colors([
|
||||
'success' => ['creat'],
|
||||
'info' => ['modificat'],
|
||||
'danger' => ['șters'],
|
||||
'warning' => ['restaurat'],
|
||||
]),
|
||||
Tables\Columns\TextColumn::make('subject_type')
|
||||
->label('Tip')
|
||||
->formatStateUsing(fn ($s) => $s ? class_basename($s) : '—'),
|
||||
Tables\Columns\TextColumn::make('subject_id')->label('ID')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('causer.name')->label('De către')->placeholder('Sistem'),
|
||||
Tables\Columns\TextColumn::make('attribute_changes')
|
||||
->label('Detalii')
|
||||
->formatStateUsing(function ($state) {
|
||||
if (! $state) return '—';
|
||||
$arr = is_string($state) ? json_decode($state, true) : $state;
|
||||
$changes = $arr['attributes'] ?? [];
|
||||
return collect($changes)
|
||||
->map(fn ($v, $k) => "{$k}: " . (is_scalar($v) ? \Illuminate\Support\Str::limit((string)$v, 30) : '—'))
|
||||
->take(3)->implode(', ');
|
||||
})
|
||||
->wrap(),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('description')
|
||||
->label('Acțiune')
|
||||
->options(['creat' => 'creat', 'modificat' => 'modificat', 'șters' => 'șters']),
|
||||
Tables\Filters\Filter::make('today')
|
||||
->label('Astăzi')
|
||||
->query(fn ($q) => $q->whereDate('created_at', today())),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->actions([])
|
||||
->paginated([25, 50, 100]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListActivities::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\ActivityResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\ActivityResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListActivities extends ListRecords
|
||||
{
|
||||
protected static string $resource = ActivityResource::class;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources;
|
||||
|
||||
use App\Filament\Tenant\Resources\EmployeeProfileResource\Pages;
|
||||
use App\Models\Tenant\EmployeeProfile;
|
||||
use App\Models\Tenant\User;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class EmployeeProfileResource extends Resource
|
||||
{
|
||||
protected static ?string $model = EmployeeProfile::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-identification';
|
||||
|
||||
protected static ?string $navigationLabel = 'Angajați';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Finanțe';
|
||||
|
||||
protected static ?string $modelLabel = 'angajat';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'angajați';
|
||||
|
||||
protected static ?int $navigationSort = 52;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Schemas\Components\Section::make('Profil')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\Select::make('user_id')
|
||||
->label('Utilizator')
|
||||
->options(fn () => User::orderBy('name')->pluck('name', 'id'))
|
||||
->searchable()
|
||||
->required()
|
||||
->unique(ignoreRecord: true),
|
||||
Forms\Components\TextInput::make('position')->label('Funcție')->maxLength(120),
|
||||
Forms\Components\DatePicker::make('hire_date')->label('Angajat din'),
|
||||
]),
|
||||
Schemas\Components\Section::make('Salariu & comisioane')
|
||||
->columns(3)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('base_salary')->label('Salariu bază')->numeric()->default(0),
|
||||
Forms\Components\TextInput::make('works_pct')
|
||||
->label('% manopere')
|
||||
->numeric()->default(0)
|
||||
->suffix('%')
|
||||
->helperText('% din venitul manoperelor finalizate.'),
|
||||
Forms\Components\TextInput::make('parts_pct')
|
||||
->label('% marja piese')
|
||||
->numeric()->default(0)
|
||||
->suffix('%')
|
||||
->helperText('% din marja (sell-buy) pieselor montate.'),
|
||||
]),
|
||||
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('user.name')->label('Nume')->searchable()->sortable(),
|
||||
Tables\Columns\TextColumn::make('position')->label('Funcție')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('base_salary')->money('MDL')->alignRight(),
|
||||
Tables\Columns\TextColumn::make('works_pct')->label('% Manopere')
|
||||
->formatStateUsing(fn ($s) => $s . '%')->alignRight(),
|
||||
Tables\Columns\TextColumn::make('parts_pct')->label('% Piese')
|
||||
->formatStateUsing(fn ($s) => $s . '%')->alignRight(),
|
||||
Tables\Columns\TextColumn::make('hire_date')->date('d.m.Y')->placeholder('—'),
|
||||
])
|
||||
->actions([
|
||||
Actions\EditAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
])
|
||||
->defaultSort('user_id');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListEmployeeProfiles::route('/'),
|
||||
'create' => Pages\CreateEmployeeProfile::route('/create'),
|
||||
'edit' => Pages\EditEmployeeProfile::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\EmployeeProfileResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\EmployeeProfileResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateEmployeeProfile extends CreateRecord
|
||||
{
|
||||
protected static string $resource = EmployeeProfileResource::class;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\EmployeeProfileResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\EmployeeProfileResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditEmployeeProfile extends EditRecord
|
||||
{
|
||||
protected static string $resource = EmployeeProfileResource::class;
|
||||
|
||||
protected function getHeaderActions(): array { return [Actions\DeleteAction::make()]; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\EmployeeProfileResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\EmployeeProfileResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListEmployeeProfiles extends ListRecords
|
||||
{
|
||||
protected static string $resource = EmployeeProfileResource::class;
|
||||
|
||||
protected function getHeaderActions(): array { return [Actions\CreateAction::make()]; }
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources;
|
||||
|
||||
use App\Filament\Tenant\Resources\PayrollAdjustmentResource\Pages;
|
||||
use App\Models\Tenant\PayrollAdjustment;
|
||||
use App\Models\Tenant\User;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class PayrollAdjustmentResource extends Resource
|
||||
{
|
||||
protected static ?string $model = PayrollAdjustment::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-adjustments-horizontal';
|
||||
|
||||
protected static ?string $navigationLabel = 'Bonusuri & avansuri';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Finanțe';
|
||||
|
||||
protected static ?string $modelLabel = 'ajustare';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'bonusuri/avansuri';
|
||||
|
||||
protected static ?int $navigationSort = 54;
|
||||
|
||||
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\Select::make('type')
|
||||
->options(PayrollAdjustment::TYPES)
|
||||
->default('bonus')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('amount')->label('Sumă')->numeric()->required(),
|
||||
Forms\Components\TextInput::make('period')
|
||||
->label('Perioadă (YYYY-MM)')
|
||||
->placeholder(now()->format('Y-m'))
|
||||
->regex('/^\d{4}-\d{2}$/')
|
||||
->required(),
|
||||
Forms\Components\DatePicker::make('date')->default(today())->required(),
|
||||
Forms\Components\TextInput::make('reason')->label('Motiv')->maxLength(160),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('date')->date('d.m.Y')->sortable(),
|
||||
Tables\Columns\TextColumn::make('user.name')->label('Utilizator')->searchable(),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->formatStateUsing(fn ($s) => PayrollAdjustment::TYPES[$s] ?? $s)
|
||||
->badge()
|
||||
->colors([
|
||||
'success' => ['bonus'],
|
||||
'danger' => ['fine'],
|
||||
'warning' => ['advance'],
|
||||
]),
|
||||
Tables\Columns\TextColumn::make('period'),
|
||||
Tables\Columns\TextColumn::make('amount')->money('MDL')->alignRight(),
|
||||
Tables\Columns\TextColumn::make('reason')->limit(40),
|
||||
Tables\Columns\IconColumn::make('applied')->boolean()->label('Aplicat'),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('type')->options(PayrollAdjustment::TYPES),
|
||||
Tables\Filters\SelectFilter::make('user_id')
|
||||
->label('Utilizator')
|
||||
->options(fn () => User::pluck('name', 'id')),
|
||||
])
|
||||
->actions([
|
||||
Actions\EditAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
])
|
||||
->defaultSort('date', 'desc');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListPayrollAdjustments::route('/'),
|
||||
'create' => Pages\CreatePayrollAdjustment::route('/create'),
|
||||
'edit' => Pages\EditPayrollAdjustment::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\PayrollAdjustmentResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\PayrollAdjustmentResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePayrollAdjustment extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PayrollAdjustmentResource::class;
|
||||
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\PayrollAdjustmentResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\PayrollAdjustmentResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPayrollAdjustment extends EditRecord
|
||||
{
|
||||
protected static string $resource = PayrollAdjustmentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array { return [Actions\DeleteAction::make()]; }
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\PayrollAdjustmentResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\PayrollAdjustmentResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPayrollAdjustments extends ListRecords
|
||||
{
|
||||
protected static string $resource = PayrollAdjustmentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array { return [Actions\CreateAction::make()]; }
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\PayrollRunResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\PayrollRunResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePayrollRun extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PayrollRunResource::class;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\PayrollRunResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\PayrollRunResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPayrollRun extends EditRecord
|
||||
{
|
||||
protected static string $resource = PayrollRunResource::class;
|
||||
|
||||
protected function getHeaderActions(): array { return [Actions\DeleteAction::make()]; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\PayrollRunResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\PayrollRunResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPayrollRuns extends ListRecords
|
||||
{
|
||||
protected static string $resource = PayrollRunResource::class;
|
||||
|
||||
protected function getHeaderActions(): array { return [Actions\CreateAction::make()]; }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use App\Tenancy\TenantManager;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
|
||||
/**
|
||||
* Adds Spatie ActivityLog with sensible defaults + auto-fills company_id
|
||||
* on every activity row so the audit trail stays tenant-scoped.
|
||||
*
|
||||
* Use on tenant models you want audited (Client, Vehicle, WorkOrder, ...).
|
||||
*/
|
||||
trait Auditable
|
||||
{
|
||||
use LogsActivity;
|
||||
|
||||
public function getActivitylogOptions(): LogOptions
|
||||
{
|
||||
return LogOptions::defaults()
|
||||
->logFillable()
|
||||
->logOnlyDirty()
|
||||
->dontSubmitEmptyLogs()
|
||||
->setDescriptionForEvent(fn (string $event) => match ($event) {
|
||||
'created' => 'creat',
|
||||
'updated' => 'modificat',
|
||||
'deleted' => 'șters',
|
||||
'restored' => 'restaurat',
|
||||
default => $event,
|
||||
});
|
||||
}
|
||||
|
||||
public function tapActivity(Activity $activity, string $eventName): void
|
||||
{
|
||||
// Auto-attach company_id if available.
|
||||
$tenantId = app(TenantManager::class)->currentId() ?: ($this->company_id ?? null);
|
||||
if ($tenantId) {
|
||||
$activity->company_id = $tenantId;
|
||||
}
|
||||
// Auto-attach causer if logged in.
|
||||
if (auth()->check() && ! $activity->causer_id) {
|
||||
$activity->causer_type = get_class(auth()->user());
|
||||
$activity->causer_id = auth()->id();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models\Tenant;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use App\Models\Concerns\Auditable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
@@ -10,7 +11,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Client extends Model
|
||||
{
|
||||
use BelongsToTenant, SoftDeletes;
|
||||
use Auditable, BelongsToTenant, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'company_id', 'type', 'name', 'company_name',
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
namespace App\Models\Tenant;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use App\Models\Concerns\Auditable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Deal extends Model
|
||||
{
|
||||
use BelongsToTenant, SoftDeletes;
|
||||
use Auditable, BelongsToTenant, SoftDeletes;
|
||||
|
||||
public const STAGES = [
|
||||
'new' => 'Nou',
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Tenant;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class EmployeeProfile extends Model
|
||||
{
|
||||
use BelongsToTenant, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'company_id', 'user_id', 'position',
|
||||
'base_salary', 'works_pct', 'parts_pct',
|
||||
'hire_date', 'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'base_salary' => 'decimal:2',
|
||||
'works_pct' => 'decimal:2',
|
||||
'parts_pct' => 'decimal:2',
|
||||
'hire_date' => 'date',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,14 @@
|
||||
namespace App\Models\Tenant;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use App\Models\Concerns\Auditable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Expense extends Model
|
||||
{
|
||||
use BelongsToTenant, SoftDeletes;
|
||||
use Auditable, BelongsToTenant, SoftDeletes;
|
||||
|
||||
public const CATEGORIES = [
|
||||
'salary' => 'Salariu',
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
namespace App\Models\Tenant;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use App\Models\Concerns\Auditable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Lead extends Model
|
||||
{
|
||||
use BelongsToTenant, SoftDeletes;
|
||||
use Auditable, BelongsToTenant, SoftDeletes;
|
||||
|
||||
public const STATUSES = [
|
||||
'new' => 'Nou',
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
namespace App\Models\Tenant;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use App\Models\Concerns\Auditable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Payment extends Model
|
||||
{
|
||||
use BelongsToTenant, SoftDeletes;
|
||||
use Auditable, BelongsToTenant, SoftDeletes;
|
||||
|
||||
public const METHODS = [
|
||||
'cash' => 'Numerar',
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Tenant;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class PayrollAdjustment extends Model
|
||||
{
|
||||
use BelongsToTenant, SoftDeletes;
|
||||
|
||||
public const TYPES = [
|
||||
'bonus' => 'Bonus',
|
||||
'fine' => 'Penalizare',
|
||||
'advance' => 'Avans',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'company_id', 'user_id', 'type', 'amount',
|
||||
'period', 'date', 'reason', 'applied',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'amount' => 'decimal:2',
|
||||
'date' => 'date',
|
||||
'applied' => 'boolean',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Tenant;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PayrollRun extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
|
||||
protected $fillable = [
|
||||
'company_id', 'user_id', 'period',
|
||||
'base', 'works_revenue', 'works_pct_amount',
|
||||
'parts_margin', 'parts_pct_amount',
|
||||
'bonus', 'fines', 'advance', 'total',
|
||||
'paid', 'paid_at', 'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'base' => 'decimal:2',
|
||||
'works_revenue' => 'decimal:2',
|
||||
'works_pct_amount' => 'decimal:2',
|
||||
'parts_margin' => 'decimal:2',
|
||||
'parts_pct_amount' => 'decimal:2',
|
||||
'bonus' => 'decimal:2',
|
||||
'fines' => 'decimal:2',
|
||||
'advance' => 'decimal:2',
|
||||
'total' => 'decimal:2',
|
||||
'paid' => 'boolean',
|
||||
'paid_at' => 'date',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,14 @@
|
||||
namespace App\Models\Tenant;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use App\Models\Concerns\Auditable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Vehicle extends Model
|
||||
{
|
||||
use BelongsToTenant, SoftDeletes;
|
||||
use Auditable, BelongsToTenant, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'company_id', 'client_id',
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models\Tenant;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use App\Models\Concerns\Auditable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
@@ -10,7 +11,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class WorkOrder extends Model
|
||||
{
|
||||
use BelongsToTenant, SoftDeletes;
|
||||
use Auditable, BelongsToTenant, SoftDeletes;
|
||||
|
||||
public const STATUSES = [
|
||||
'new' => 'Nou',
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Tenant\EmployeeProfile;
|
||||
use App\Models\Tenant\PayrollAdjustment;
|
||||
use App\Models\Tenant\PayrollRun;
|
||||
use App\Models\Tenant\WorkOrderPart;
|
||||
use App\Models\Tenant\WorkOrderWork;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PayrollCalculator
|
||||
{
|
||||
/**
|
||||
* Compute (or upsert) the payroll run for a given user + month.
|
||||
* Period format: YYYY-MM.
|
||||
*/
|
||||
public function compute(int $userId, string $period, bool $persist = true): PayrollRun
|
||||
{
|
||||
$start = Carbon::createFromFormat('Y-m', $period)->startOfMonth();
|
||||
$end = (clone $start)->endOfMonth();
|
||||
|
||||
$profile = EmployeeProfile::where('user_id', $userId)->first();
|
||||
$base = (float) ($profile?->base_salary ?? 0);
|
||||
$worksPct = (float) ($profile?->works_pct ?? 0);
|
||||
$partsPct = (float) ($profile?->parts_pct ?? 0);
|
||||
|
||||
// Manopere finalizate de utilizator în perioadă.
|
||||
$worksRevenue = (float) WorkOrderWork::where('master_id', $userId)
|
||||
->where('status', 'done')
|
||||
->whereBetween('updated_at', [$start, $end])
|
||||
->sum('total');
|
||||
$worksPctAmount = round($worksRevenue * $worksPct / 100, 2);
|
||||
|
||||
// Marja pe piesele montate de utilizator (nu există FK direct, aprox via work_order.master_id)
|
||||
$partsMargin = (float) WorkOrderPart::where('status', 'installed')
|
||||
->whereBetween('updated_at', [$start, $end])
|
||||
->whereHas('workOrder', fn ($q) => $q->where('master_id', $userId))
|
||||
->get()
|
||||
->sum(fn ($p) => ((float) $p->sell_price - (float) $p->buy_price) * (float) $p->qty);
|
||||
$partsPctAmount = round($partsMargin * $partsPct / 100, 2);
|
||||
|
||||
// Bonus / penalizări / avans pe perioadă.
|
||||
$adjustments = PayrollAdjustment::where('user_id', $userId)
|
||||
->where('period', $period)
|
||||
->get();
|
||||
$bonus = (float) $adjustments->where('type', 'bonus')->sum('amount');
|
||||
$fines = (float) $adjustments->where('type', 'fine')->sum('amount');
|
||||
$advance = (float) $adjustments->where('type', 'advance')->sum('amount');
|
||||
|
||||
$total = round(
|
||||
$base + $worksPctAmount + $partsPctAmount + $bonus - $fines - $advance,
|
||||
2
|
||||
);
|
||||
|
||||
$attrs = [
|
||||
'base' => $base,
|
||||
'works_revenue' => $worksRevenue,
|
||||
'works_pct_amount' => $worksPctAmount,
|
||||
'parts_margin' => $partsMargin,
|
||||
'parts_pct_amount' => $partsPctAmount,
|
||||
'bonus' => $bonus,
|
||||
'fines' => $fines,
|
||||
'advance' => $advance,
|
||||
'total' => max(0, $total),
|
||||
];
|
||||
|
||||
if (! $persist) {
|
||||
return new PayrollRun(['user_id' => $userId, 'period' => $period] + $attrs);
|
||||
}
|
||||
|
||||
$run = PayrollRun::updateOrCreate(
|
||||
['user_id' => $userId, 'period' => $period, 'company_id' => app(\App\Tenancy\TenantManager::class)->currentId()],
|
||||
$attrs
|
||||
);
|
||||
|
||||
return $run;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user