From a18465cacff3614783eb808ddc4a3e6d6aef7098 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Tue, 9 Sep 2025 16:23:48 -0300 Subject: [PATCH] Seeds --- app/tests/extension/Seeds/Bancos.php | 23 ++++++++ app/tests/extension/Seeds/BrokerContracts.php | 45 +++++++++++++++ app/tests/extension/Seeds/Brokers.php | 50 +++++++++++++++++ app/tests/extension/Seeds/Promotions.php | 55 +++++++++++++++++++ .../extension/Seeds/ProyectoTipoUnidad.php | 42 ++++++++++++++ app/tests/extension/Seeds/Unidades.php | 47 ++++++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 app/tests/extension/Seeds/Bancos.php create mode 100644 app/tests/extension/Seeds/BrokerContracts.php create mode 100644 app/tests/extension/Seeds/Brokers.php create mode 100644 app/tests/extension/Seeds/Promotions.php create mode 100644 app/tests/extension/Seeds/ProyectoTipoUnidad.php create mode 100644 app/tests/extension/Seeds/Unidades.php diff --git a/app/tests/extension/Seeds/Bancos.php b/app/tests/extension/Seeds/Bancos.php new file mode 100644 index 0000000..631e595 --- /dev/null +++ b/app/tests/extension/Seeds/Bancos.php @@ -0,0 +1,23 @@ + $this->faker->company, + ]; + } + + $this->table('banco') + ->insertValues($data) + ->save(); + } +} diff --git a/app/tests/extension/Seeds/BrokerContracts.php b/app/tests/extension/Seeds/BrokerContracts.php new file mode 100644 index 0000000..9adac33 --- /dev/null +++ b/app/tests/extension/Seeds/BrokerContracts.php @@ -0,0 +1,45 @@ +loadValues('brokers', columns: 'rut'); + $projects = $this->loadValues('proyecto', columns: 'id'); + + $data = []; + foreach ($projects as $project) { + $count = $this->faker->numberBetween(1, count($brokers)); + for ($i = 0; $i < $count; $i++) { + $data []= [ + 'broker_rut' => $brokers[$i], + 'project_id' => $project, + 'commission' => $this->faker->randomFloat(4, 0, 1), + ]; + } + } + $this->table('broker_contracts')->insertValues($data)->save(); + + $contracts = $this->loadValues('broker_contracts', columns: 'id'); + $stateData = []; + foreach ($contracts as $contract) { + $stateData[]= [ + 'contract_id' => $contract, + 'date' => $this->faker->dateTimeBetween('-1 year'), + 'type' => 1 + ]; + } + $this->table('broker_contract_states')->insertValues($stateData)->save(); + } +} diff --git a/app/tests/extension/Seeds/Brokers.php b/app/tests/extension/Seeds/Brokers.php new file mode 100644 index 0000000..7ac1a73 --- /dev/null +++ b/app/tests/extension/Seeds/Brokers.php @@ -0,0 +1,50 @@ +loadValues('direccion', columns: 'id'); + + + + $count = 10; + $contactData = []; + for($i = 0; $i < $count; $i++) { + $rut = $this->faker->rut(false, false); + $contactData[]= [ + 'rut' => $rut, + 'digit' => $this->faker->digitoVerificador($rut), + 'name' => $this->faker->name, + 'email' => $this->faker->email, + 'phone' => $this->faker->phoneNumber, + 'address_id' => $this->faker->randomElement($addresses) + ]; + } + $this->table('broker_contacts')->insertValues($contactData)->save(); + + $contacts = $this->loadValues('broker_contacts', columns: 'id'); + + $data = []; + $brokerData = []; + for($i = 0; $i < $count; $i ++) { + $rut = $this->faker->rut(false, false); + $data[] = [ + 'rut' => $rut, + 'digit' => $this->faker->digitoVerificador($rut), + 'name' => $this->faker->word + ]; + $brokerData []= [ + 'broker_rut' => $rut, + 'representante_id' => $this->faker->randomElement($contacts), + 'legal_name' => $this->faker->company + ]; + } + + $this->table('brokers')->insertValues($data)->save(); + $this->table('broker_data')->insertValues($brokerData)->save(); + } +} diff --git a/app/tests/extension/Seeds/Promotions.php b/app/tests/extension/Seeds/Promotions.php new file mode 100644 index 0000000..00c5293 --- /dev/null +++ b/app/tests/extension/Seeds/Promotions.php @@ -0,0 +1,55 @@ +loadValues('proyecto', columns: 'id'); + + $data = []; + $count = $this->faker->numberBetween(1, 10); + for ($i = 0; $i < $count; $i++) { + $start = $this->faker->dateTimeBetween('-1 year'); + $end = $this->faker->dateTimeBetween($start, $start->add(new DateInterval('P1Y'))); + $data[] = [ + 'description' => $this->faker->sentence, + 'type' => 1, + 'amount' => $this->faker->randomFloat(2, 0, 1), + 'start_date' => $start, + 'end_date' => $end, + 'valid_until' => $this->faker->dateTimeBetween($end, $end->add(new DateInterval('P1M'))), + 'state' => 1, + ]; + } + $this->table('promotions')->insertValues($data)->save(); + + $promotions = $this->loadValues('promotions', columns: 'id'); + + $data = []; + foreach ($projects as $project) { + $hasPromo = $this->faker->boolean(10); + if (!$hasPromo) { + continue; + } + + $data []= [ + 'promotion_id' => $this->faker->randomElement($promotions), + 'project_id' => $project, + ]; + } + if (count($data) > 0) { + $this->table('promotion_projects')->insertValues($data)->save(); + } + } +} diff --git a/app/tests/extension/Seeds/ProyectoTipoUnidad.php b/app/tests/extension/Seeds/ProyectoTipoUnidad.php new file mode 100644 index 0000000..da2c384 --- /dev/null +++ b/app/tests/extension/Seeds/ProyectoTipoUnidad.php @@ -0,0 +1,42 @@ +loadValues('proyecto', columns: 'id'); + $types = $this->loadValues('tipo_unidad', columns: 'id'); + + $data = []; + foreach ($projects as $project) { + foreach ($types as $type) { + $count = $this->faker->numberBetween(1, 10); + for ($i = 0; $i < $count; $i++) { + $name = $this->faker->word; + $data []= [ + 'proyecto' => $project, + 'tipo' => $type, + 'nombre' => $name, + 'abreviacion' => substr($name, 0, 3), + 'm2' => $this->faker->randomFloat(2, 10, 100), + 'logia' => $this->faker->optional(.3, 0)->randomFloat(2, 1, 5), + 'terraza' => $this->faker->optional(.3, 0)->randomFloat(2, 2, 30), + 'descripcion' => $this->faker->sentence, + ]; + } + } + } + + $this->table('proyecto_tipo_unidad')->insertValues($data)->save(); + } +} diff --git a/app/tests/extension/Seeds/Unidades.php b/app/tests/extension/Seeds/Unidades.php new file mode 100644 index 0000000..b879509 --- /dev/null +++ b/app/tests/extension/Seeds/Unidades.php @@ -0,0 +1,47 @@ +loadValues('proyecto_tipo_unidad', columns: ['id', 'proyecto', 'tipo', 'm2', 'logia', 'terraza']); + + $data = []; + foreach ($ptus as $s => $ptu) { + $count = $this->faker->numberBetween(1, 10); + $abr = $this->faker->word; + $orientation = $this->faker->randomElement(['N', 'NO', 'NP', 'S', 'SO', 'SP', 'P', 'O']); + + for ($i = 0; $i < $count; $i++) { + $data[] = [ + 'proyecto' => $ptu['proyecto'], + 'tipo' => $ptu['tipo'], + 'subtipo' => $s, + 'piso' => $i + 2, + 'descripcion' => ($i + 2) * 100 + $s, + 'abreviacion' => $abr, + 'm2' => $ptu['m2'], + 'logia' => $ptu['logia'], + 'cubierta' => 0, + 'terraza' => $ptu['terraza'], + 'orientacion' => $orientation, + 'costo_inmobiliaria' => $this->faker->randomFloat(2, 1000, 3000), + 'pt' => $ptu['id'], + 'valor' => $this->faker->randomFloat(2, 1000, 3000), + ]; + } + } + + $this->table('unidad')->insertValues($data)->save(); + } +}