AssociadosRelatorioSeeder.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Database\Seeders;
  3. use App\Enums\UserStatusEnum;
  4. use App\Enums\UserTypeEnum;
  5. use App\Models\User;
  6. use Carbon\Carbon;
  7. use Faker\Factory as Faker;
  8. use Illuminate\Database\Seeder;
  9. use Illuminate\Support\Facades\Hash;
  10. class AssociadosRelatorioSeeder extends Seeder
  11. {
  12. private array $positions = [1, 2, 3, 4, 5, 6, 7, 8];
  13. private array $sectors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  14. public function run(): void
  15. {
  16. $faker = Faker::create('pt_BR');
  17. // ── Tab 1: Novos Associados ─────────────────────────────────────────
  18. // 25 associados ativos cadastrados em maio/2026
  19. for ($i = 1; $i <= 25; $i++) {
  20. $createdAt = Carbon::create(2026, 5, rand(1, 18), rand(8, 17), rand(0, 59));
  21. User::create([
  22. 'name' => $faker->name(),
  23. 'email' => "novo.associado{$i}@serprati.test",
  24. 'password' => Hash::make('senha123'),
  25. 'type' => UserTypeEnum::ASSOCIADO,
  26. 'language' => 'pt',
  27. 'status' => UserStatusEnum::ACTIVE,
  28. 'cpf' => $this->formatCpf($i),
  29. 'registration' => 'NA' . str_pad($i, 4, '0', STR_PAD_LEFT),
  30. 'phone' => $faker->cellphoneNumber(),
  31. 'admission_date' => Carbon::create(2026, 5, rand(1, 18)),
  32. 'expiry_date' => Carbon::create(2027, 5, rand(1, 18)),
  33. 'position_id' => $this->positions[($i - 1) % count($this->positions)],
  34. 'sector_id' => $this->sectors[($i - 1) % count($this->sectors)],
  35. 'created_at' => $createdAt,
  36. 'updated_at' => $createdAt,
  37. ]);
  38. }
  39. // ── Tab 3: Exclusões do mês ─────────────────────────────────────────
  40. // 25 associados inativos excluídos em maio/2026, cadastrados antes
  41. for ($i = 1; $i <= 25; $i++) {
  42. $createdAt = Carbon::create(2026, rand(1, 4), rand(1, 28), rand(8, 17), rand(0, 59));
  43. $excludedAt = Carbon::create(2026, 5, rand(1, 18), rand(8, 17), rand(0, 59));
  44. $offset = $i + 25;
  45. User::create([
  46. 'name' => $faker->name(),
  47. 'email' => "excluido.associado{$i}@serprati.test",
  48. 'password' => Hash::make('senha123'),
  49. 'type' => UserTypeEnum::ASSOCIADO,
  50. 'language' => 'pt',
  51. 'status' => UserStatusEnum::INACTIVE,
  52. 'cpf' => $this->formatCpf($offset),
  53. 'registration' => 'EX' . str_pad($i, 4, '0', STR_PAD_LEFT),
  54. 'phone' => rand(0, 1) ? $faker->cellphoneNumber() : null,
  55. 'admission_date' => $createdAt->copy()->subMonths(rand(1, 6)),
  56. 'expiry_date' => null,
  57. 'position_id' => $this->positions[($i - 1) % count($this->positions)],
  58. 'sector_id' => $this->sectors[($i - 1) % count($this->sectors)],
  59. 'excluded_at' => $excludedAt,
  60. 'created_at' => $createdAt,
  61. 'updated_at' => $excludedAt,
  62. ]);
  63. }
  64. $this->command->info('AssociadosRelatorioSeeder: 25 novos associados + 25 exclusões do mês criados.');
  65. }
  66. private function formatCpf(int $n): string
  67. {
  68. $base = str_pad($n, 9, '0', STR_PAD_LEFT);
  69. return substr($base, 0, 3) . '.' . substr($base, 3, 3) . '.' . substr($base, 6, 3) . '-00';
  70. }
  71. }