DeveloperTestSeeder.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace Database\Seeders;
  3. use App\Models\City;
  4. use App\Models\Unit;
  5. use App\Models\UnitPartner;
  6. use App\Models\UnitUser;
  7. use App\Models\User;
  8. use App\Models\UserType;
  9. use Illuminate\Database\Seeder;
  10. class DeveloperTestSeeder extends Seeder
  11. {
  12. public function run(): void
  13. {
  14. $cities = City::with('state')
  15. ->whereIn('name', ['São Paulo', 'Campinas', 'Santos'])
  16. ->get()
  17. ->keyBy('name');
  18. $fallbackCity = City::with('state')->firstOrFail();
  19. $accessPassword = 'S@ft2080.';
  20. $units = [
  21. [
  22. 'city' => 'São Paulo',
  23. 'attributes' => [
  24. 'name' => 'Ginástica do Cérebro Paulista',
  25. 'fantasy_name' => 'GC Paulista',
  26. 'social_reason' => 'GC Paulista Desenvolvimento Cognitivo Ltda.',
  27. 'cnpj' => '11.723.853/0001-78',
  28. 'state_registration' => '110042490114',
  29. 'name_responsible' => 'Mariana Oliveira',
  30. 'street' => 'Avenida Paulista',
  31. 'address_number' => '1000',
  32. 'postal_code' => '01310-100',
  33. 'neighborhood' => 'Bela Vista',
  34. 'complement' => 'Conjunto 101',
  35. 'email' => 'paulista@dev.ginasticadocerebro.com.br',
  36. 'secondary_email' => 'administrativo.paulista@dev.ginasticadocerebro.com.br',
  37. 'phone_number' => '(11) 3251-1000',
  38. 'cell_number' => '(11) 99991-1000',
  39. ],
  40. 'partners' => [
  41. [
  42. 'name' => 'Mariana Oliveira',
  43. 'cpf' => '52998224725',
  44. 'role' => 'Sócia Administradora',
  45. 'participation' => 60,
  46. 'email' => 'mariana.oliveira@dev.ginasticadocerebro.com.br',
  47. 'cell_number' => '(11) 99991-1001',
  48. ],
  49. [
  50. 'name' => 'Carlos Henrique Lima',
  51. 'cpf' => '16899535009',
  52. 'role' => 'Sócio',
  53. 'participation' => 40,
  54. 'email' => 'carlos.lima@dev.ginasticadocerebro.com.br',
  55. ],
  56. ],
  57. ],
  58. [
  59. 'city' => 'Campinas',
  60. 'attributes' => [
  61. 'name' => 'Ginástica do Cérebro Campinas',
  62. 'fantasy_name' => 'GC Campinas',
  63. 'social_reason' => 'GC Campinas Treinamento Mental Ltda.',
  64. 'cnpj' => '45.997.418/0001-53',
  65. 'state_registration' => '244567890116',
  66. 'name_responsible' => 'Fernanda Souza',
  67. 'street' => 'Avenida José de Souza Campos',
  68. 'address_number' => '750',
  69. 'postal_code' => '13025-320',
  70. 'neighborhood' => 'Cambuí',
  71. 'complement' => 'Sala 12',
  72. 'email' => 'campinas@dev.ginasticadocerebro.com.br',
  73. 'secondary_email' => null,
  74. 'phone_number' => null,
  75. 'cell_number' => '(19) 99992-2000',
  76. ],
  77. 'partners' => [
  78. [
  79. 'name' => 'Fernanda Souza',
  80. 'cpf' => '11144477735',
  81. 'email' => 'fernanda.souza@dev.ginasticadocerebro.com.br',
  82. ],
  83. [
  84. 'name' => 'Ricardo Martins',
  85. 'cpf' => '12345678909',
  86. 'role' => 'Sócio',
  87. 'participation' => 35,
  88. 'email' => 'ricardo.martins@dev.ginasticadocerebro.com.br',
  89. 'cell_number' => '(19) 99992-2001',
  90. ],
  91. ],
  92. ],
  93. [
  94. 'city' => 'Santos',
  95. 'attributes' => [
  96. 'name' => 'Ginástica do Cérebro Santos',
  97. 'fantasy_name' => 'GC Santos',
  98. 'social_reason' => 'GC Santos Educação e Desenvolvimento Ltda.',
  99. 'cnpj' => '27.865.757/0001-02',
  100. 'state_registration' => null,
  101. 'name_responsible' => 'Ana Paula Ribeiro',
  102. 'street' => 'Avenida Ana Costa',
  103. 'address_number' => '450',
  104. 'postal_code' => '11060-002',
  105. 'neighborhood' => 'Gonzaga',
  106. 'complement' => null,
  107. 'email' => 'santos@dev.ginasticadocerebro.com.br',
  108. 'secondary_email' => 'administrativo.santos@dev.ginasticadocerebro.com.br',
  109. 'phone_number' => '(13) 3284-3000',
  110. 'cell_number' => '(13) 99993-3000',
  111. ],
  112. 'partners' => [
  113. [
  114. 'name' => 'Ana Paula Ribeiro',
  115. 'cpf' => '98765432100',
  116. 'role' => 'Sócia Administradora',
  117. 'participation' => 70,
  118. 'email' => 'ana.ribeiro@dev.ginasticadocerebro.com.br',
  119. ],
  120. [
  121. 'name' => 'Lucas Almeida',
  122. 'cpf' => '39053344705',
  123. 'role' => 'Sócio',
  124. 'participation' => 30,
  125. 'email' => 'lucas.almeida@dev.ginasticadocerebro.com.br',
  126. ],
  127. ],
  128. ],
  129. ];
  130. foreach ($units as $unitData) {
  131. $city = $cities->get($unitData['city']) ?? $fallbackCity;
  132. $attributes = array_merge($unitData['attributes'], [
  133. 'city_id' => $city->id,
  134. 'state_id' => $city->state_id,
  135. ]);
  136. $unit = Unit::withTrashed()->updateOrCreate(
  137. ['cnpj' => $attributes['cnpj']],
  138. $attributes,
  139. );
  140. $unit->restore();
  141. $userType = UserType::updateOrCreate(
  142. [
  143. 'scope_key' => "unit:{$unit->id}",
  144. 'slug' => 'ADMIN_FRANCHISEE',
  145. ],
  146. [
  147. 'unit_id' => $unit->id,
  148. 'system_key' => 'ADMIN_FRANCHISEE',
  149. 'label' => 'Administrador',
  150. 'is_system' => true,
  151. 'access_scope' => 'unit',
  152. ],
  153. );
  154. foreach ($unitData['partners'] as $partnerData) {
  155. $partner = UnitPartner::withTrashed()->updateOrCreate(
  156. [
  157. 'unit_id' => $unit->id,
  158. 'cpf' => $partnerData['cpf'],
  159. ],
  160. array_merge($partnerData, [
  161. 'unit_id' => $unit->id,
  162. 'city_id' => $city->id,
  163. 'state_id' => $city->state_id,
  164. ]),
  165. );
  166. $partner->restore();
  167. $user = User::updateOrCreate(
  168. ['email' => $partnerData['email']],
  169. [
  170. 'name' => $partnerData['name'],
  171. 'cpf' => $partnerData['cpf'],
  172. 'password' => $accessPassword,
  173. 'status' => 'ACTIVE',
  174. 'user_type' => 'ADMIN_FRANCHISEE',
  175. 'access_scope' => 'unit',
  176. 'state_id' => $city->state_id,
  177. 'deleted_at' => null,
  178. ],
  179. );
  180. UnitUser::updateOrCreate(
  181. [
  182. 'unit_id' => $unit->id,
  183. 'user_id' => $user->id,
  184. ],
  185. [
  186. 'user_type_id' => $userType->id,
  187. 'deleted_at' => null,
  188. ],
  189. );
  190. }
  191. }
  192. }
  193. }