| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace Database\Seeders;
- use App\Enums\UserStatusEnum;
- use App\Enums\UserTypeEnum;
- use App\Models\User;
- use Carbon\Carbon;
- use Faker\Factory as Faker;
- use Illuminate\Database\Seeder;
- use Illuminate\Support\Facades\Hash;
- class AssociadosRelatorioSeeder extends Seeder
- {
- private array $positions = [1, 2, 3, 4, 5, 6, 7, 8];
- private array $sectors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
- public function run(): void
- {
- $faker = Faker::create('pt_BR');
- // ── Tab 1: Novos Associados ─────────────────────────────────────────
- // 25 associados ativos cadastrados em maio/2026
- for ($i = 1; $i <= 25; $i++) {
- $createdAt = Carbon::create(2026, 5, rand(1, 18), rand(8, 17), rand(0, 59));
- User::create([
- 'name' => $faker->name(),
- 'email' => "novo.associado{$i}@serprati.test",
- 'password' => Hash::make('senha123'),
- 'type' => UserTypeEnum::ASSOCIADO,
- 'language' => 'pt',
- 'status' => UserStatusEnum::ACTIVE,
- 'cpf' => $this->formatCpf($i),
- 'registration' => 'NA' . str_pad($i, 4, '0', STR_PAD_LEFT),
- 'phone' => $faker->cellphoneNumber(),
- 'admission_date' => Carbon::create(2026, 5, rand(1, 18)),
- 'expiry_date' => Carbon::create(2027, 5, rand(1, 18)),
- 'position_id' => $this->positions[($i - 1) % count($this->positions)],
- 'sector_id' => $this->sectors[($i - 1) % count($this->sectors)],
- 'created_at' => $createdAt,
- 'updated_at' => $createdAt,
- ]);
- }
- // ── Tab 3: Exclusões do mês ─────────────────────────────────────────
- // 25 associados inativos excluídos em maio/2026, cadastrados antes
- for ($i = 1; $i <= 25; $i++) {
- $createdAt = Carbon::create(2026, rand(1, 4), rand(1, 28), rand(8, 17), rand(0, 59));
- $excludedAt = Carbon::create(2026, 5, rand(1, 18), rand(8, 17), rand(0, 59));
- $offset = $i + 25;
- User::create([
- 'name' => $faker->name(),
- 'email' => "excluido.associado{$i}@serprati.test",
- 'password' => Hash::make('senha123'),
- 'type' => UserTypeEnum::ASSOCIADO,
- 'language' => 'pt',
- 'status' => UserStatusEnum::INACTIVE,
- 'cpf' => $this->formatCpf($offset),
- 'registration' => 'EX' . str_pad($i, 4, '0', STR_PAD_LEFT),
- 'phone' => rand(0, 1) ? $faker->cellphoneNumber() : null,
- 'admission_date' => $createdAt->copy()->subMonths(rand(1, 6)),
- 'expiry_date' => null,
- 'position_id' => $this->positions[($i - 1) % count($this->positions)],
- 'sector_id' => $this->sectors[($i - 1) % count($this->sectors)],
- 'excluded_at' => $excludedAt,
- 'created_at' => $createdAt,
- 'updated_at' => $excludedAt,
- ]);
- }
- $this->command->info('AssociadosRelatorioSeeder: 25 novos associados + 25 exclusões do mês criados.');
- }
- private function formatCpf(int $n): string
- {
- $base = str_pad($n, 9, '0', STR_PAD_LEFT);
- return substr($base, 0, 3) . '.' . substr($base, 3, 3) . '.' . substr($base, 6, 3) . '-00';
- }
- }
|