Seeds
This commit is contained in:
23
app/tests/extension/Seeds/Bancos.php
Normal file
23
app/tests/extension/Seeds/Bancos.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class Bancos extends AbstractSeed
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$count = 10;
|
||||
|
||||
$data = [];
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$data[] = [
|
||||
'nombre' => $this->faker->company,
|
||||
];
|
||||
}
|
||||
|
||||
$this->table('banco')
|
||||
->insertValues($data)
|
||||
->save();
|
||||
}
|
||||
}
|
45
app/tests/extension/Seeds/BrokerContracts.php
Normal file
45
app/tests/extension/Seeds/BrokerContracts.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class BrokerContracts extends AbstractSeed
|
||||
{
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
Brokers::class,
|
||||
Proyectos::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$brokers = $this->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();
|
||||
}
|
||||
}
|
50
app/tests/extension/Seeds/Brokers.php
Normal file
50
app/tests/extension/Seeds/Brokers.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class Brokers extends AbstractSeed
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$addresses = $this->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();
|
||||
}
|
||||
}
|
55
app/tests/extension/Seeds/Promotions.php
Normal file
55
app/tests/extension/Seeds/Promotions.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use DateInterval;
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class Promotions extends AbstractSeed
|
||||
{
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
Proyectos::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$projects = $this->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();
|
||||
}
|
||||
}
|
||||
}
|
42
app/tests/extension/Seeds/ProyectoTipoUnidad.php
Normal file
42
app/tests/extension/Seeds/ProyectoTipoUnidad.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class ProyectoTipoUnidad extends AbstractSeed
|
||||
{
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
Proyectos::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$projects = $this->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();
|
||||
}
|
||||
}
|
47
app/tests/extension/Seeds/Unidades.php
Normal file
47
app/tests/extension/Seeds/Unidades.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class Unidades extends AbstractSeed
|
||||
{
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
ProyectoTipoUnidad::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$ptus = $this->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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user