DeveloperTestSeeder.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <?php
  2. namespace Database\Seeders;
  3. use App\Enums\UserTypeEnum;
  4. use App\Models\City;
  5. use App\Models\ClassPackage;
  6. use App\Models\Franchisee;
  7. use App\Models\Product;
  8. use App\Models\State;
  9. use App\Models\Unit;
  10. use App\Models\UnitUser;
  11. use App\Models\User;
  12. use Illuminate\Database\Seeder;
  13. use Illuminate\Support\Facades\DB;
  14. class DeveloperTestSeeder extends Seeder
  15. {
  16. public function run(): void
  17. {
  18. $this->seedProducts();
  19. $this->seedClassPackages();
  20. $this->seedClassPackageProducts();
  21. $this->seedTestFranchisees();
  22. }
  23. private function seedProducts(): void
  24. {
  25. $products = [
  26. [
  27. 'name' => 'Apostila Nível 1',
  28. 'sku' => 'AP-NV1',
  29. 'barcode' => '7890001000001',
  30. 'price_cost' => 18.00,
  31. 'price_sale' => 35.00,
  32. 'measure_unit' => 'UN',
  33. 'kit' => false,
  34. 'visible_franchisee' => true,
  35. 'weight' => 0.300,
  36. 'length' => 29.7,
  37. 'height' => 21.0,
  38. ],
  39. [
  40. 'name' => 'Apostila Nível 2',
  41. 'sku' => 'AP-NV2',
  42. 'barcode' => '7890001000002',
  43. 'price_cost' => 18.00,
  44. 'price_sale' => 35.00,
  45. 'measure_unit' => 'UN',
  46. 'kit' => false,
  47. 'visible_franchisee' => true,
  48. 'weight' => 0.300,
  49. 'length' => 29.7,
  50. 'height' => 21.0,
  51. ],
  52. [
  53. 'name' => 'Apostila Nível 3',
  54. 'sku' => 'AP-NV3',
  55. 'barcode' => '7890001000003',
  56. 'price_cost' => 18.00,
  57. 'price_sale' => 35.00,
  58. 'measure_unit' => 'UN',
  59. 'kit' => false,
  60. 'visible_franchisee' => true,
  61. 'weight' => 0.300,
  62. 'length' => 29.7,
  63. 'height' => 21.0,
  64. ],
  65. [
  66. 'name' => 'Kit Material Didático Básico',
  67. 'sku' => 'KIT-MAT-BAS',
  68. 'barcode' => '7890001000010',
  69. 'price_cost' => 45.00,
  70. 'price_sale' => 89.90,
  71. 'measure_unit' => 'KIT',
  72. 'kit' => true,
  73. 'visible_franchisee' => true,
  74. 'weight' => 0.800,
  75. 'length' => 30.0,
  76. 'height' => 22.0,
  77. ],
  78. [
  79. 'name' => 'Kit Material Didático Completo',
  80. 'sku' => 'KIT-MAT-COMP',
  81. 'barcode' => '7890001000011',
  82. 'price_cost' => 90.00,
  83. 'price_sale' => 169.90,
  84. 'measure_unit' => 'KIT',
  85. 'kit' => true,
  86. 'visible_franchisee' => true,
  87. 'weight' => 1.500,
  88. 'length' => 30.0,
  89. 'height' => 22.0,
  90. ],
  91. [
  92. 'name' => 'Caderno de Atividades',
  93. 'sku' => 'CAD-ATI',
  94. 'barcode' => '7890001000020',
  95. 'price_cost' => 12.00,
  96. 'price_sale' => 24.90,
  97. 'measure_unit' => 'UN',
  98. 'kit' => false,
  99. 'visible_franchisee' => true,
  100. 'weight' => 0.200,
  101. 'length' => 29.7,
  102. 'height' => 21.0,
  103. ],
  104. [
  105. 'name' => 'Livro do Aluno — Ginástica do Cérebro',
  106. 'sku' => 'LV-ALUNO-GC',
  107. 'barcode' => '7890001000030',
  108. 'price_cost' => 32.00,
  109. 'price_sale' => 59.90,
  110. 'measure_unit' => 'UN',
  111. 'kit' => false,
  112. 'visible_franchisee' => true,
  113. 'weight' => 0.450,
  114. 'length' => 23.0,
  115. 'height' => 16.0,
  116. ],
  117. [
  118. 'name' => 'Camiseta Ginástica do Cérebro',
  119. 'sku' => 'CAM-GC',
  120. 'barcode' => '7890001000040',
  121. 'price_cost' => 20.00,
  122. 'price_sale' => 49.90,
  123. 'measure_unit' => 'UN',
  124. 'kit' => false,
  125. 'visible_franchisee' => true,
  126. 'weight' => 0.200,
  127. 'length' => 30.0,
  128. 'height' => 20.0,
  129. ],
  130. [
  131. 'name' => 'Pasta do Aluno',
  132. 'sku' => 'PAST-ALUNO',
  133. 'barcode' => '7890001000050',
  134. 'price_cost' => 5.00,
  135. 'price_sale' => 12.90,
  136. 'measure_unit' => 'UN',
  137. 'kit' => false,
  138. 'visible_franchisee' => true,
  139. 'weight' => 0.100,
  140. 'length' => 33.0,
  141. 'height' => 23.0,
  142. ],
  143. [
  144. 'name' => 'Certificado de Conclusão',
  145. 'sku' => 'CERT-CONCL',
  146. 'barcode' => '7890001000060',
  147. 'price_cost' => 2.00,
  148. 'price_sale' => 5.00,
  149. 'measure_unit' => 'UN',
  150. 'kit' => false,
  151. 'visible_franchisee' => false,
  152. 'weight' => 0.050,
  153. 'length' => 29.7,
  154. 'height' => 21.0,
  155. ],
  156. ];
  157. foreach ($products as $product) {
  158. Product::firstOrCreate(['sku' => $product['sku']], $product);
  159. }
  160. }
  161. private function seedClassPackages(): void
  162. {
  163. $packages = [
  164. [
  165. 'name' => 'Plano Anual',
  166. 'quantity_classes' => 78,
  167. 'contract_value' => 1198.90,
  168. 'contract_material_value' => 299.90,
  169. 'contract_register_value' => 89.90,
  170. 'contrat_discount_value' => null,
  171. ],
  172. [
  173. 'name' => 'Plano Mensal',
  174. 'quantity_classes' => 4,
  175. 'contract_value' => 1198.90,
  176. 'contract_material_value' => 299.90,
  177. 'contract_register_value' => 89.90,
  178. 'contrat_discount_value' => null,
  179. ],
  180. [
  181. 'name' => 'Plano VIP',
  182. 'quantity_classes' => 4,
  183. 'contract_value' => 1198.90,
  184. 'contract_material_value' => 299.90,
  185. 'contract_register_value' => 89.90,
  186. 'contrat_discount_value' => null,
  187. ],
  188. [
  189. 'name' => 'Plano Trimestral',
  190. 'quantity_classes' => 12,
  191. 'contract_value' => 1198.90,
  192. 'contract_material_value' => 299.90,
  193. 'contract_register_value' => 89.90,
  194. 'contrat_discount_value' => null,
  195. ],
  196. [
  197. 'name' => 'Plano Semestral',
  198. 'quantity_classes' => 24,
  199. 'contract_value' => 1198.90,
  200. 'contract_material_value' => 299.90,
  201. 'contract_register_value' => 89.90,
  202. 'contrat_discount_value' => null,
  203. ],
  204. [
  205. 'name' => 'Plano Lúdico',
  206. 'quantity_classes' => 24,
  207. 'contract_value' => 1198.90,
  208. 'contract_material_value' => 299.90,
  209. 'contract_register_value' => 89.90,
  210. 'contrat_discount_value' => null,
  211. ],
  212. [
  213. 'name' => 'Plano Play',
  214. 'quantity_classes' => 78,
  215. 'contract_value' => 1198.90,
  216. 'contract_material_value' => 299.90,
  217. 'contract_register_value' => 89.90,
  218. 'contrat_discount_value' => null,
  219. ],
  220. [
  221. 'name' => 'Plano Plus',
  222. 'quantity_classes' => 4,
  223. 'contract_value' => 1198.90,
  224. 'contract_material_value' => 299.90,
  225. 'contract_register_value' => 89.90,
  226. 'contrat_discount_value' => null,
  227. ],
  228. [
  229. 'name' => 'Plano Mais Conhecimento',
  230. 'quantity_classes' => 4,
  231. 'contract_value' => 1198.90,
  232. 'contract_material_value' => 299.90,
  233. 'contract_register_value' => 89.90,
  234. 'contrat_discount_value' => null,
  235. ],
  236. [
  237. 'name' => 'Plano Reforço',
  238. 'quantity_classes' => 12,
  239. 'contract_value' => 1198.90,
  240. 'contract_material_value' => 299.90,
  241. 'contract_register_value' => 89.90,
  242. 'contrat_discount_value' => null,
  243. ],
  244. [
  245. 'name' => 'Plano Aprendiz',
  246. 'quantity_classes' => 24,
  247. 'contract_value' => 1198.90,
  248. 'contract_material_value' => 299.90,
  249. 'contract_register_value' => 89.90,
  250. 'contrat_discount_value' => null,
  251. ],
  252. [
  253. 'name' => 'Plano Senior',
  254. 'quantity_classes' => 24,
  255. 'contract_value' => 1198.90,
  256. 'contract_material_value' => 299.90,
  257. 'contract_register_value' => 89.90,
  258. 'contrat_discount_value' => null,
  259. ],
  260. ];
  261. foreach ($packages as $package) {
  262. ClassPackage::firstOrCreate(['name' => $package['name']], $package);
  263. }
  264. }
  265. private function seedClassPackageProducts(): void
  266. {
  267. // Base products included in every package
  268. $baseSkus = ['AP-NV1', 'CAD-ATI', 'PAST-ALUNO'];
  269. // Additional products for kit-based packages
  270. $kitSkus = ['KIT-MAT-BAS', 'LV-ALUNO-GC'];
  271. $kitPackageNames = ['Plano VIP', 'Plano Plus', 'Plano Anual', 'Plano Play'];
  272. $products = Product::whereIn('sku', array_merge($baseSkus, $kitSkus))->get()->keyBy('sku');
  273. $packages = ClassPackage::all();
  274. foreach ($packages as $package) {
  275. $skus = in_array($package->name, $kitPackageNames)
  276. ? array_merge($baseSkus, $kitSkus)
  277. : $baseSkus;
  278. foreach ($skus as $sku) {
  279. $product = $products->get($sku);
  280. if (!$product) {
  281. continue;
  282. }
  283. DB::table('class_package_products')->insertOrIgnore([
  284. 'class_package_id' => $package->id,
  285. 'product_id' => $product->id,
  286. 'quantity' => 1,
  287. 'price' => $product->price_sale,
  288. 'created_at' => now(),
  289. 'updated_at' => now(),
  290. ]);
  291. }
  292. }
  293. }
  294. private function seedTestFranchisees(): void
  295. {
  296. $prState = State::where('code', 'PR')->first();
  297. $alState = State::where('code', 'AL')->first();
  298. $toledoCity = City::where('name', 'Toledo')->where('state_id', $prState->id)->first();
  299. $maceioCity = City::where('name', 'Maceió')->where('state_id', $alState->id)->first();
  300. $gabriel = User::firstOrCreate(
  301. ['email' => 'gabriel@softpar.inf.br'],
  302. [
  303. 'name' => 'Gabriel',
  304. 'password' => 'S@ft2080.',
  305. 'user_type' => UserTypeEnum::ADMIN_FRANCHISEE,
  306. ]
  307. );
  308. $heloisa = User::firstOrCreate(
  309. ['email' => 'heloisa@softpar.inf.br'],
  310. [
  311. 'name' => 'Heloisa',
  312. 'password' => 'S@ft2080.',
  313. 'user_type' => UserTypeEnum::ADMIN_FRANCHISEE,
  314. ]
  315. );
  316. $gabrielFranchisee = Franchisee::firstOrCreate(
  317. ['cpf' => '000.000.001-00'],
  318. [
  319. 'name' => 'Gabriel (Teste)',
  320. 'street' => 'Rua Sete de Setembro',
  321. 'address_number' => '100',
  322. 'neighborhood' => 'Centro',
  323. 'postal_code' => '85900-000',
  324. 'city_id' => $toledoCity->id,
  325. 'state_id' => $prState->id,
  326. ]
  327. );
  328. $heloisaFranchisee = Franchisee::firstOrCreate(
  329. ['cpf' => '000.000.002-00'],
  330. [
  331. 'name' => 'Heloisa (Teste)',
  332. 'street' => 'Rua do Comércio',
  333. 'address_number' => '200',
  334. 'neighborhood' => 'Centro',
  335. 'postal_code' => '57000-000',
  336. 'city_id' => $maceioCity->id,
  337. 'state_id' => $alState->id,
  338. ]
  339. );
  340. $gabrielUnit = Unit::firstOrCreate(
  341. ['cnpj' => '00.000.001/0001-00'],
  342. [
  343. 'fantasy_name' => 'Unidade Gabriel (Teste)',
  344. 'social_reason' => 'Unidade Gabriel Teste LTDA',
  345. 'phone_number' => '(45) 99999-0001',
  346. 'street' => 'Rua Sete de Setembro',
  347. 'address_number' => '100',
  348. 'neighborhood' => 'Centro',
  349. 'postal_code' => '85900-000',
  350. 'city_id' => $toledoCity->id,
  351. 'state_id' => $prState->id,
  352. 'email' => 'unidade.gabriel@gc.com.br',
  353. 'name_responsible' => 'Gabriel',
  354. ]
  355. );
  356. $heloisaUnit = Unit::firstOrCreate(
  357. ['cnpj' => '00.000.002/0001-00'],
  358. [
  359. 'fantasy_name' => 'Unidade Heloisa (Teste)',
  360. 'social_reason' => 'Unidade Heloisa Teste LTDA',
  361. 'phone_number' => '(82) 99999-0002',
  362. 'street' => 'Rua do Comércio',
  363. 'address_number' => '200',
  364. 'neighborhood' => 'Centro',
  365. 'postal_code' => '57000-000',
  366. 'city_id' => $maceioCity->id,
  367. 'state_id' => $alState->id,
  368. 'email' => 'unidade.heloisa@gc.com.br',
  369. 'name_responsible' => 'Heloisa',
  370. ]
  371. );
  372. // Link franchisees to units
  373. DB::table('franchisee_units')->insertOrIgnore([
  374. [
  375. 'franchisee_id' => $gabrielFranchisee->id,
  376. 'unit_id' => $gabrielUnit->id,
  377. 'created_at' => now(),
  378. 'updated_at' => now(),
  379. ],
  380. [
  381. 'franchisee_id' => $heloisaFranchisee->id,
  382. 'unit_id' => $heloisaUnit->id,
  383. 'created_at' => now(),
  384. 'updated_at' => now(),
  385. ],
  386. ]);
  387. // Link users to units
  388. UnitUser::firstOrCreate(['unit_id' => $gabrielUnit->id, 'user_id' => $gabriel->id]);
  389. UnitUser::firstOrCreate(['unit_id' => $heloisaUnit->id, 'user_id' => $heloisa->id]);
  390. // Link all class packages to both test units
  391. $packageIds = ClassPackage::pluck('id');
  392. foreach ($packageIds as $packageId) {
  393. DB::table('class_package_units')->insertOrIgnore([
  394. [
  395. 'class_package_id' => $packageId,
  396. 'unit_id' => $gabrielUnit->id,
  397. 'visible' => true,
  398. 'created_at' => now(),
  399. 'updated_at' => now(),
  400. ],
  401. [
  402. 'class_package_id' => $packageId,
  403. 'unit_id' => $heloisaUnit->id,
  404. 'visible' => true,
  405. 'created_at' => now(),
  406. 'updated_at' => now(),
  407. ],
  408. ]);
  409. }
  410. }
  411. }