Explorar o código

feat: add seeder para ambiente de development com units e partners ja cadastrados

Gustavo Mantovani hai 1 día
pai
achega
cb993574ae
Modificáronse 1 ficheiros con 196 adicións e 1 borrados
  1. 196 1
      database/seeders/DeveloperTestSeeder.php

+ 196 - 1
database/seeders/DeveloperTestSeeder.php

@@ -2,12 +2,207 @@
 
 namespace Database\Seeders;
 
+use App\Models\City;
+use App\Models\Unit;
+use App\Models\UnitPartner;
+use App\Models\UnitUser;
+use App\Models\User;
+use App\Models\UserType;
 use Illuminate\Database\Seeder;
 
 class DeveloperTestSeeder extends Seeder
 {
     public function run(): void
     {
-        //
+        $cities = City::with('state')
+            ->whereIn('name', ['São Paulo', 'Campinas', 'Santos'])
+            ->get()
+            ->keyBy('name');
+
+        $fallbackCity = City::with('state')->firstOrFail();
+
+        $accessPassword = 'S@ft2080.';
+
+        $units = [
+            [
+                'city' => 'São Paulo',
+                'attributes' => [
+                    'name'               => 'Ginástica do Cérebro Paulista',
+                    'fantasy_name'       => 'GC Paulista',
+                    'social_reason'      => 'GC Paulista Desenvolvimento Cognitivo Ltda.',
+                    'cnpj'               => '11.723.853/0001-78',
+                    'state_registration' => '110042490114',
+                    'name_responsible'   => 'Mariana Oliveira',
+                    'street'             => 'Avenida Paulista',
+                    'address_number'     => '1000',
+                    'postal_code'        => '01310-100',
+                    'neighborhood'       => 'Bela Vista',
+                    'complement'         => 'Conjunto 101',
+                    'email'              => 'paulista@dev.ginasticadocerebro.com.br',
+                    'secondary_email'    => 'administrativo.paulista@dev.ginasticadocerebro.com.br',
+                    'phone_number'       => '(11) 3251-1000',
+                    'cell_number'        => '(11) 99991-1000',
+                ],
+                'partners' => [
+                    [
+                        'name'          => 'Mariana Oliveira',
+                        'cpf'           => '52998224725',
+                        'role'          => 'Sócia Administradora',
+                        'participation' => 60,
+                        'email'         => 'mariana.oliveira@dev.ginasticadocerebro.com.br',
+                        'cell_number'   => '(11) 99991-1001',
+                    ],
+                    [
+                        'name'          => 'Carlos Henrique Lima',
+                        'cpf'           => '16899535009',
+                        'role'          => 'Sócio',
+                        'participation' => 40,
+                        'email'         => 'carlos.lima@dev.ginasticadocerebro.com.br',
+                    ],
+                ],
+            ],
+            [
+                'city' => 'Campinas',
+                'attributes' => [
+                    'name'               => 'Ginástica do Cérebro Campinas',
+                    'fantasy_name'       => 'GC Campinas',
+                    'social_reason'      => 'GC Campinas Treinamento Mental Ltda.',
+                    'cnpj'               => '45.997.418/0001-53',
+                    'state_registration' => '244567890116',
+                    'name_responsible'   => 'Fernanda Souza',
+                    'street'             => 'Avenida José de Souza Campos',
+                    'address_number'     => '750',
+                    'postal_code'        => '13025-320',
+                    'neighborhood'       => 'Cambuí',
+                    'complement'         => 'Sala 12',
+                    'email'              => 'campinas@dev.ginasticadocerebro.com.br',
+                    'secondary_email'    => null,
+                    'phone_number'       => null,
+                    'cell_number'        => '(19) 99992-2000',
+                ],
+                'partners' => [
+                    [
+                        'name'  => 'Fernanda Souza',
+                        'cpf'   => '11144477735',
+                        'email' => 'fernanda.souza@dev.ginasticadocerebro.com.br',
+                    ],
+                    [
+                        'name'          => 'Ricardo Martins',
+                        'cpf'           => '12345678909',
+                        'role'          => 'Sócio',
+                        'participation' => 35,
+                        'email'         => 'ricardo.martins@dev.ginasticadocerebro.com.br',
+                        'cell_number'   => '(19) 99992-2001',
+                    ],
+                ],
+            ],
+            [
+                'city' => 'Santos',
+                'attributes' => [
+                    'name'               => 'Ginástica do Cérebro Santos',
+                    'fantasy_name'       => 'GC Santos',
+                    'social_reason'      => 'GC Santos Educação e Desenvolvimento Ltda.',
+                    'cnpj'               => '27.865.757/0001-02',
+                    'state_registration' => null,
+                    'name_responsible'   => 'Ana Paula Ribeiro',
+                    'street'             => 'Avenida Ana Costa',
+                    'address_number'     => '450',
+                    'postal_code'        => '11060-002',
+                    'neighborhood'       => 'Gonzaga',
+                    'complement'         => null,
+                    'email'              => 'santos@dev.ginasticadocerebro.com.br',
+                    'secondary_email'    => 'administrativo.santos@dev.ginasticadocerebro.com.br',
+                    'phone_number'       => '(13) 3284-3000',
+                    'cell_number'        => '(13) 99993-3000',
+                ],
+                'partners' => [
+                    [
+                        'name'          => 'Ana Paula Ribeiro',
+                        'cpf'           => '98765432100',
+                        'role'          => 'Sócia Administradora',
+                        'participation' => 70,
+                        'email'         => 'ana.ribeiro@dev.ginasticadocerebro.com.br',
+                    ],
+                    [
+                        'name'          => 'Lucas Almeida',
+                        'cpf'           => '39053344705',
+                        'role'          => 'Sócio',
+                        'participation' => 30,
+                        'email'         => 'lucas.almeida@dev.ginasticadocerebro.com.br',
+                    ],
+                ],
+            ],
+        ];
+
+        foreach ($units as $unitData) {
+            $city = $cities->get($unitData['city']) ?? $fallbackCity;
+
+            $attributes = array_merge($unitData['attributes'], [
+                'city_id'  => $city->id,
+                'state_id' => $city->state_id,
+            ]);
+
+            $unit = Unit::withTrashed()->updateOrCreate(
+                ['cnpj' => $attributes['cnpj']],
+                $attributes,
+            );
+
+            $unit->restore();
+
+            $userType = UserType::updateOrCreate(
+                [
+                    'scope_key' => "unit:{$unit->id}",
+                    'slug'      => 'ADMIN_FRANCHISEE',
+                ],
+                [
+                    'unit_id'      => $unit->id,
+                    'system_key'   => 'ADMIN_FRANCHISEE',
+                    'label'        => 'Administrador',
+                    'is_system'    => true,
+                    'access_scope' => 'unit',
+                ],
+            );
+
+            foreach ($unitData['partners'] as $partnerData) {
+                $partner = UnitPartner::withTrashed()->updateOrCreate(
+                    [
+                        'unit_id' => $unit->id,
+                        'cpf'     => $partnerData['cpf'],
+                    ],
+                    array_merge($partnerData, [
+                        'unit_id'  => $unit->id,
+                        'city_id'  => $city->id,
+                        'state_id' => $city->state_id,
+                    ]),
+                );
+
+                $partner->restore();
+
+                $user = User::updateOrCreate(
+                    ['email' => $partnerData['email']],
+                    [
+                        'name'         => $partnerData['name'],
+                        'cpf'          => $partnerData['cpf'],
+                        'password'     => $accessPassword,
+                        'status'       => 'ACTIVE',
+                        'user_type'    => 'ADMIN_FRANCHISEE',
+                        'access_scope' => 'unit',
+                        'state_id'     => $city->state_id,
+                        'deleted_at'   => null,
+                    ],
+                );
+
+                UnitUser::updateOrCreate(
+                    [
+                        'unit_id' => $unit->id,
+                        'user_id' => $user->id,
+                    ],
+                    [
+                        'user_type_id' => $userType->id,
+                        'deleted_at'   => null,
+                    ],
+                );
+            }
+        }
     }
 }