|
|
@@ -2,26 +2,14 @@
|
|
|
|
|
|
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
|
|
|
@@ -163,274 +151,4 @@ private function seedProducts(): void
|
|
|
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(),
|
|
|
- ],
|
|
|
- ]);
|
|
|
- }
|
|
|
- }
|
|
|
}
|