2026-03-11 23:33:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Database\Factories;
|
|
|
|
|
|
2026-03-12 18:25:32 +00:00
|
|
|
use App\Enums\DeclarationPriority;
|
|
|
|
|
use App\Enums\DeclarationStatus;
|
|
|
|
|
use App\Enums\DeclarationType;
|
2026-03-11 23:33:10 +00:00
|
|
|
use App\Models\Client;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-03-12 18:25:32 +00:00
|
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Declaration>
|
2026-03-11 23:33:10 +00:00
|
|
|
*/
|
2026-03-12 18:25:32 +00:00
|
|
|
class DeclarationFactory extends Factory
|
2026-03-11 23:33:10 +00:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Define the model's default state.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, mixed>
|
|
|
|
|
*/
|
|
|
|
|
public function definition(): array
|
|
|
|
|
{
|
|
|
|
|
$workspace = Workspace::factory()->create();
|
|
|
|
|
$client = Client::factory()->create(['workspace_id' => $workspace->id]);
|
|
|
|
|
|
|
|
|
|
$year = fake()->numberBetween(2024, 2026);
|
2026-03-12 18:25:32 +00:00
|
|
|
$excludeOldVat = array_filter(DeclarationType::getValues(), fn ($v) => $v !== 'vat');
|
2026-03-11 23:33:10 +00:00
|
|
|
$type = fake()->randomElement(array_values($excludeOldVat));
|
|
|
|
|
|
|
|
|
|
$isVatMonthly = $type === 'vat_monthly';
|
|
|
|
|
$isVatQuarterly = $type === 'vat_quarterly';
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'workspace_id' => $workspace->id,
|
|
|
|
|
'client_id' => $client->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'),
|
2026-03-12 18:25:32 +00:00
|
|
|
'status' => DeclarationStatus::Created,
|
|
|
|
|
'priority' => fake()->randomElement(DeclarationPriority::getValues()),
|
2026-03-11 23:33:10 +00:00
|
|
|
'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',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|