| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- <?php
- namespace Database\Seeders;
- use App\Enums\UserTypeEnum;
- use App\Models\City;
- use App\Models\ClassPackage;
- use App\Models\Franchisee;
- use App\Models\Product;
- use App\Models\State;
- use App\Models\Unit;
- use App\Models\UnitUser;
- use App\Models\User;
- use Illuminate\Database\Seeder;
- use Illuminate\Support\Facades\DB;
- class DeveloperTestSeeder extends Seeder
- {
- public function run(): void
- {
- $this->seedProducts();
- $this->seedClassPackages();
- $this->seedClassPackageProducts();
- $this->seedTestFranchisees();
- }
- private function seedProducts(): void
- {
- $products = [
- [
- 'name' => 'Apostila Nível 1',
- 'sku' => 'AP-NV1',
- 'barcode' => '7890001000001',
- 'price_cost' => 18.00,
- 'price_sale' => 35.00,
- 'measure_unit' => 'UN',
- 'kit' => false,
- 'visible_franchisee' => true,
- 'weight' => 0.300,
- 'length' => 29.7,
- 'height' => 21.0,
- ],
- [
- 'name' => 'Apostila Nível 2',
- 'sku' => 'AP-NV2',
- 'barcode' => '7890001000002',
- 'price_cost' => 18.00,
- 'price_sale' => 35.00,
- 'measure_unit' => 'UN',
- 'kit' => false,
- 'visible_franchisee' => true,
- 'weight' => 0.300,
- 'length' => 29.7,
- 'height' => 21.0,
- ],
- [
- 'name' => 'Apostila Nível 3',
- 'sku' => 'AP-NV3',
- 'barcode' => '7890001000003',
- 'price_cost' => 18.00,
- 'price_sale' => 35.00,
- 'measure_unit' => 'UN',
- 'kit' => false,
- 'visible_franchisee' => true,
- 'weight' => 0.300,
- 'length' => 29.7,
- 'height' => 21.0,
- ],
- [
- 'name' => 'Kit Material Didático Básico',
- 'sku' => 'KIT-MAT-BAS',
- 'barcode' => '7890001000010',
- 'price_cost' => 45.00,
- 'price_sale' => 89.90,
- 'measure_unit' => 'KIT',
- 'kit' => true,
- 'visible_franchisee' => true,
- 'weight' => 0.800,
- 'length' => 30.0,
- 'height' => 22.0,
- ],
- [
- 'name' => 'Kit Material Didático Completo',
- 'sku' => 'KIT-MAT-COMP',
- 'barcode' => '7890001000011',
- 'price_cost' => 90.00,
- 'price_sale' => 169.90,
- 'measure_unit' => 'KIT',
- 'kit' => true,
- 'visible_franchisee' => true,
- 'weight' => 1.500,
- 'length' => 30.0,
- 'height' => 22.0,
- ],
- [
- 'name' => 'Caderno de Atividades',
- 'sku' => 'CAD-ATI',
- 'barcode' => '7890001000020',
- 'price_cost' => 12.00,
- 'price_sale' => 24.90,
- 'measure_unit' => 'UN',
- 'kit' => false,
- 'visible_franchisee' => true,
- 'weight' => 0.200,
- 'length' => 29.7,
- 'height' => 21.0,
- ],
- [
- 'name' => 'Livro do Aluno — Ginástica do Cérebro',
- 'sku' => 'LV-ALUNO-GC',
- 'barcode' => '7890001000030',
- 'price_cost' => 32.00,
- 'price_sale' => 59.90,
- 'measure_unit' => 'UN',
- 'kit' => false,
- 'visible_franchisee' => true,
- 'weight' => 0.450,
- 'length' => 23.0,
- 'height' => 16.0,
- ],
- [
- 'name' => 'Camiseta Ginástica do Cérebro',
- 'sku' => 'CAM-GC',
- 'barcode' => '7890001000040',
- 'price_cost' => 20.00,
- 'price_sale' => 49.90,
- 'measure_unit' => 'UN',
- 'kit' => false,
- 'visible_franchisee' => true,
- 'weight' => 0.200,
- 'length' => 30.0,
- 'height' => 20.0,
- ],
- [
- 'name' => 'Pasta do Aluno',
- 'sku' => 'PAST-ALUNO',
- 'barcode' => '7890001000050',
- 'price_cost' => 5.00,
- 'price_sale' => 12.90,
- 'measure_unit' => 'UN',
- 'kit' => false,
- 'visible_franchisee' => true,
- 'weight' => 0.100,
- 'length' => 33.0,
- 'height' => 23.0,
- ],
- [
- 'name' => 'Certificado de Conclusão',
- 'sku' => 'CERT-CONCL',
- 'barcode' => '7890001000060',
- 'price_cost' => 2.00,
- 'price_sale' => 5.00,
- 'measure_unit' => 'UN',
- 'kit' => false,
- 'visible_franchisee' => false,
- 'weight' => 0.050,
- 'length' => 29.7,
- 'height' => 21.0,
- ],
- ];
- foreach ($products as $product) {
- Product::firstOrCreate(['sku' => $product['sku']], $product);
- }
- }
- private function seedClassPackages(): void
- {
- $packages = [
- [
- 'name' => 'Plano Anual',
- 'quantity_classes' => 78,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- [
- 'name' => 'Plano Mensal',
- 'quantity_classes' => 4,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- [
- 'name' => 'Plano VIP',
- 'quantity_classes' => 4,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- [
- 'name' => 'Plano Trimestral',
- 'quantity_classes' => 12,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- [
- 'name' => 'Plano Semestral',
- 'quantity_classes' => 24,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- [
- 'name' => 'Plano Lúdico',
- 'quantity_classes' => 24,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- [
- 'name' => 'Plano Play',
- 'quantity_classes' => 78,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- [
- 'name' => 'Plano Plus',
- 'quantity_classes' => 4,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- [
- 'name' => 'Plano Mais Conhecimento',
- 'quantity_classes' => 4,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- [
- 'name' => 'Plano Reforço',
- 'quantity_classes' => 12,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- [
- 'name' => 'Plano Aprendiz',
- 'quantity_classes' => 24,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- [
- 'name' => 'Plano Senior',
- 'quantity_classes' => 24,
- 'contract_value' => 1198.90,
- 'contract_material_value' => 299.90,
- 'contract_register_value' => 89.90,
- 'contrat_discount_value' => null,
- ],
- ];
- foreach ($packages as $package) {
- ClassPackage::firstOrCreate(['name' => $package['name']], $package);
- }
- }
- private function seedClassPackageProducts(): void
- {
- // Base products included in every package
- $baseSkus = ['AP-NV1', 'CAD-ATI', 'PAST-ALUNO'];
- // Additional products for kit-based packages
- $kitSkus = ['KIT-MAT-BAS', 'LV-ALUNO-GC'];
- $kitPackageNames = ['Plano VIP', 'Plano Plus', 'Plano Anual', 'Plano Play'];
- $products = Product::whereIn('sku', array_merge($baseSkus, $kitSkus))->get()->keyBy('sku');
- $packages = ClassPackage::all();
- foreach ($packages as $package) {
- $skus = in_array($package->name, $kitPackageNames)
- ? array_merge($baseSkus, $kitSkus)
- : $baseSkus;
- foreach ($skus as $sku) {
- $product = $products->get($sku);
- if (!$product) {
- continue;
- }
- DB::table('class_package_products')->insertOrIgnore([
- 'class_package_id' => $package->id,
- 'product_id' => $product->id,
- 'quantity' => 1,
- 'price' => $product->price_sale,
- 'created_at' => now(),
- 'updated_at' => now(),
- ]);
- }
- }
- }
- private function seedTestFranchisees(): void
- {
- $prState = State::where('code', 'PR')->first();
- $alState = State::where('code', 'AL')->first();
- $toledoCity = City::where('name', 'Toledo')->where('state_id', $prState->id)->first();
- $maceioCity = City::where('name', 'Maceió')->where('state_id', $alState->id)->first();
- $gabriel = User::firstOrCreate(
- ['email' => 'gabriel@softpar.inf.br'],
- [
- 'name' => 'Gabriel',
- 'password' => 'S@ft2080.',
- 'user_type' => UserTypeEnum::ADMIN_FRANCHISEE,
- ]
- );
- $heloisa = User::firstOrCreate(
- ['email' => 'heloisa@softpar.inf.br'],
- [
- 'name' => 'Heloisa',
- 'password' => 'S@ft2080.',
- 'user_type' => UserTypeEnum::ADMIN_FRANCHISEE,
- ]
- );
- $gabrielFranchisee = Franchisee::firstOrCreate(
- ['cpf' => '000.000.001-00'],
- [
- 'name' => 'Gabriel (Teste)',
- 'street' => 'Rua Sete de Setembro',
- 'address_number' => '100',
- 'neighborhood' => 'Centro',
- 'postal_code' => '85900-000',
- 'city_id' => $toledoCity->id,
- 'state_id' => $prState->id,
- ]
- );
- $heloisaFranchisee = Franchisee::firstOrCreate(
- ['cpf' => '000.000.002-00'],
- [
- 'name' => 'Heloisa (Teste)',
- 'street' => 'Rua do Comércio',
- 'address_number' => '200',
- 'neighborhood' => 'Centro',
- 'postal_code' => '57000-000',
- 'city_id' => $maceioCity->id,
- 'state_id' => $alState->id,
- ]
- );
- $gabrielUnit = Unit::firstOrCreate(
- ['cnpj' => '00.000.001/0001-00'],
- [
- 'fantasy_name' => 'Unidade Gabriel (Teste)',
- 'social_reason' => 'Unidade Gabriel Teste LTDA',
- 'phone_number' => '(45) 99999-0001',
- 'street' => 'Rua Sete de Setembro',
- 'address_number' => '100',
- 'neighborhood' => 'Centro',
- 'postal_code' => '85900-000',
- 'city_id' => $toledoCity->id,
- 'state_id' => $prState->id,
- 'email' => 'unidade.gabriel@gc.com.br',
- 'name_responsible' => 'Gabriel',
- ]
- );
- $heloisaUnit = Unit::firstOrCreate(
- ['cnpj' => '00.000.002/0001-00'],
- [
- 'fantasy_name' => 'Unidade Heloisa (Teste)',
- 'social_reason' => 'Unidade Heloisa Teste LTDA',
- 'phone_number' => '(82) 99999-0002',
- 'street' => 'Rua do Comércio',
- 'address_number' => '200',
- 'neighborhood' => 'Centro',
- 'postal_code' => '57000-000',
- 'city_id' => $maceioCity->id,
- 'state_id' => $alState->id,
- 'email' => 'unidade.heloisa@gc.com.br',
- 'name_responsible' => 'Heloisa',
- ]
- );
- // Link franchisees to units
- DB::table('franchisee_units')->insertOrIgnore([
- [
- 'franchisee_id' => $gabrielFranchisee->id,
- 'unit_id' => $gabrielUnit->id,
- 'created_at' => now(),
- 'updated_at' => now(),
- ],
- [
- 'franchisee_id' => $heloisaFranchisee->id,
- 'unit_id' => $heloisaUnit->id,
- 'created_at' => now(),
- 'updated_at' => now(),
- ],
- ]);
- // Link users to units
- UnitUser::firstOrCreate(['unit_id' => $gabrielUnit->id, 'user_id' => $gabriel->id]);
- UnitUser::firstOrCreate(['unit_id' => $heloisaUnit->id, 'user_id' => $heloisa->id]);
- // Link all class packages to both test units
- $packageIds = ClassPackage::pluck('id');
- foreach ($packageIds as $packageId) {
- DB::table('class_package_units')->insertOrIgnore([
- [
- 'class_package_id' => $packageId,
- 'unit_id' => $gabrielUnit->id,
- 'visible' => true,
- 'created_at' => now(),
- 'updated_at' => now(),
- ],
- [
- 'class_package_id' => $packageId,
- 'unit_id' => $heloisaUnit->id,
- 'visible' => true,
- 'created_at' => now(),
- 'updated_at' => now(),
- ],
- ]);
- }
- }
- }
|