- Rewrite DashboardController with cached role-scoped KPI aggregation (Cache::remember, 5-min TTL, Declaration::forUser scope) - Create StatCard.vue component with CVA status variants and a11y - Rewrite Dashboard.vue with 4-column KPI grid + urgent declarations table - Add mise_en_demeure status to DeclarationStatus enum with transitions - Exclude termine, mise_en_demeure, ferme from dashboard queries - Set deadline proximity red threshold to ≤5 days - Add abort(404) for non-member workspace access per architecture - Fix null-safe client access for soft-deleted clients - Fix hardcoded routes with Wayfinder type-safe imports - Fix DashboardProps.stats type to allow null - Add aria-pressed to StatCard for accessibility - Install shadcn-vue table component (11 files) - Add 11 Pest feature tests + 3 mise_en_demeure transition tests - Fix DeclarationFactory eager workspace creation causing slug collisions - 196 tests pass, 836 assertions, zero regressions
78 lines
2.6 KiB
PHP
78 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\DeclarationPriority;
|
|
use App\Enums\DeclarationStatus;
|
|
use App\Enums\DeclarationType;
|
|
use App\Models\Client;
|
|
use App\Models\Workspace;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Declaration>
|
|
*/
|
|
class DeclarationFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
$year = fake()->numberBetween(2024, 2026);
|
|
$excludeOldVat = array_filter(DeclarationType::getValues(), fn ($v) => $v !== 'vat');
|
|
$type = fake()->randomElement(array_values($excludeOldVat));
|
|
|
|
$isVatMonthly = $type === 'vat_monthly';
|
|
$isVatQuarterly = $type === 'vat_quarterly';
|
|
|
|
return [
|
|
'workspace_id' => Workspace::factory(),
|
|
'client_id' => function (array $attributes) {
|
|
return Client::factory()->create(['workspace_id' => $attributes['workspace_id']])->id;
|
|
},
|
|
'created_by' => null,
|
|
'title' => 'Déclaration '.$this->typeLabel($type).' - '.$year,
|
|
'type' => $type,
|
|
'period_year' => $year,
|
|
'period_month' => $isVatMonthly ? fake()->numberBetween(1, 12) : null,
|
|
'period_quarter' => $isVatQuarterly ? fake()->numberBetween(1, 4) : null,
|
|
'due_date' => fake()->dateTimeBetween('now', '+3 months'),
|
|
'status' => DeclarationStatus::Created,
|
|
'priority' => fake()->randomElement(DeclarationPriority::getValues()),
|
|
'assigned_to' => null,
|
|
'validated_at' => null,
|
|
'closed_at' => null,
|
|
'notes_internal' => fake()->optional(0.3)->sentence(),
|
|
'notes_client' => null,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Configure the model factory to use existing workspace and client.
|
|
*/
|
|
public function forWorkspace(Workspace $workspace): static
|
|
{
|
|
return $this->state(fn () => [
|
|
'workspace_id' => $workspace->id,
|
|
'client_id' => Client::factory()->create(['workspace_id' => $workspace->id])->id,
|
|
]);
|
|
}
|
|
|
|
private function typeLabel(string $type): string
|
|
{
|
|
return match ($type) {
|
|
'vat' => 'TVA',
|
|
'vat_monthly' => 'TVA mensuelle',
|
|
'vat_quarterly' => 'TVA trimestrielle',
|
|
'corporate_tax' => 'IS',
|
|
'income_tax' => 'IR',
|
|
'cnss' => 'CNSS',
|
|
'annual_balance' => 'Bilan',
|
|
default => 'Autre',
|
|
};
|
|
}
|
|
}
|