diff --git a/app/resources/database/seeds/Comuna.php b/app/resources/database/seeds/Comuna.php index 0c8c4b8..034fb40 100644 --- a/app/resources/database/seeds/Comuna.php +++ b/app/resources/database/seeds/Comuna.php @@ -6,6 +6,13 @@ use Phinx\Seed\AbstractSeed; class Comuna extends AbstractSeed { + public function getDependencies(): array + { + return [ + 'Provincia', + ]; + } + /** * Run Method. * @@ -29,6 +36,9 @@ class Comuna extends AbstractSeed if (str_contains($column, 'id')) { return 'id'; } + if (str_contains($column, 'provincia')) { + return 'provincia'; + } return $column; }, $columns); $data = array_map(function ($row) use ($columns) { diff --git a/app/resources/database/seeds/Provincia.php b/app/resources/database/seeds/Provincia.php index 27dda24..da3a9b2 100644 --- a/app/resources/database/seeds/Provincia.php +++ b/app/resources/database/seeds/Provincia.php @@ -6,6 +6,13 @@ use Phinx\Seed\AbstractSeed; class Provincia extends AbstractSeed { + public function getDependencies(): array + { + return [ + 'Region', + ]; + } + /** * Run Method. * @@ -29,6 +36,9 @@ class Provincia extends AbstractSeed if (str_contains($column, 'id')) { return 'id'; } + if (str_contains($column, 'region')) { + return 'region'; + } return $column; }, $columns); $data = array_map(function ($row) use ($columns) { diff --git a/app/resources/database/seeds/Region.php b/app/resources/database/seeds/Region.php index df7e812..f5c8681 100644 --- a/app/resources/database/seeds/Region.php +++ b/app/resources/database/seeds/Region.php @@ -29,6 +29,9 @@ class Region extends AbstractSeed if (str_contains($column, 'id')) { return 'id'; } + if (str_contains($column, 'numeracion')) { + return 'numeracion'; + } return $column; }, $columns); $data = array_map(function ($row) use ($columns) { diff --git a/app/resources/database/seeds/TipoPago.php b/app/resources/database/seeds/TipoPago.php new file mode 100644 index 0000000..648937c --- /dev/null +++ b/app/resources/database/seeds/TipoPago.php @@ -0,0 +1,52 @@ +table('tipo_pago'); + $data = [ + [ + 'descripcion' => 'cheque', + ], + [ + 'descripcion' => 'carta de resguardo', + ], + [ + 'descripcion' => 'vale vista' + ], + [ + 'descripcion' => 'deposito', + ], + [ + 'descripcion' => 'efectivo', + ], + [ + 'descripcion' => 'tarjeta de credito', + ], + [ + 'descripcion' => 'transferencia electronica', + ], + [ + 'descripcion' => 'virtual', + ] + ]; + + $table->truncate(); + $table + ->insert($data) + ->saveData(); + } +} diff --git a/app/src/Repository/Venta/Unidad.php b/app/src/Repository/Venta/Unidad.php index f49044d..f95843c 100644 --- a/app/src/Repository/Venta/Unidad.php +++ b/app/src/Repository/Venta/Unidad.php @@ -23,7 +23,6 @@ class Unidad extends Ideal\Repository ->register('pt', (new Implement\Repository\Mapper()) ->setProperty('proyectoTipoUnidad') ->setFunction(function($data) { - var_dump($data['pt']); return $this->proyectoTipoUnidadService->getById($data['pt']); })); return $this->parseData(new Model\Venta\Unidad(), $data, $map); diff --git a/app/src/Service/Venta/Cuota.php b/app/src/Service/Venta/Cuota.php index 5647c70..b8d3a56 100644 --- a/app/src/Service/Venta/Cuota.php +++ b/app/src/Service/Venta/Cuota.php @@ -9,6 +9,7 @@ use Psr\Log\LoggerInterface; use Incoviba\Common\Ideal; use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Exception\ServiceAction\Create; +use Incoviba\Exception\ServiceAction\Read; use Incoviba\Repository; use Incoviba\Model; @@ -23,6 +24,20 @@ class Cuota extends Ideal\Service parent::__construct($logger); } + /** + * @param int $cuota_id + * @return Model\Venta\Cuota + * @throws Read + */ + public function getById(int $cuota_id): Model\Venta\Cuota + { + try { + return $this->process($this->cuotaRepository->fetchById($cuota_id)); + } catch (EmptyResult $exception) { + throw new Read(__CLASS__, $exception); + } + } + public function pendientes(): array { $cuotas = $this->cuotaRepository->fetchPendientes(); @@ -130,4 +145,9 @@ class Cuota extends Ideal\Service throw new Create(__CLASS__, $exception); } } + + protected function process(Model\Venta\Cuota $cuota): Model\Venta\Cuota + { + return $cuota; + } } diff --git a/app/test.bootstrap.php b/app/test.bootstrap.php index e7a4a64..4b79867 100644 --- a/app/test.bootstrap.php +++ b/app/test.bootstrap.php @@ -171,8 +171,8 @@ spl_autoload_register(function($className) { }); $bootstrap = new TestBootstrap($_ENV); -$resetDatabase = ($_ENV['RESET_DATABASE'] === 'true') ?? false; -$debug = ($_ENV['DEBUG'] === 'true') ?? false; +$resetDatabase = (array_key_exists('RESET_DATABASE', $_ENV) and $_ENV['RESET_DATABASE'] === 'true') ?? false; +$debug = (array_key_exists('DEBUG', $_ENV) and $_ENV['DEBUG'] === 'true') ?? false; Benchmark::execute([$bootstrap, 'run'], ['debug' => $debug]); Benchmark::print(); diff --git a/app/tests/integration/QueueTest.php b/app/tests/integration/QueueTest.php index f23dadd..5731cb6 100644 --- a/app/tests/integration/QueueTest.php +++ b/app/tests/integration/QueueTest.php @@ -96,27 +96,42 @@ class QueueTest extends TestCase $propiedad = $propiedadRepository->create($propiedadData); $propiedad = $propiedadRepository->save($propiedad); $fecha = $faker->date; + $pieData = [ + 'valor' => 10000, + 'cuotas' => 12, + 'fecha' => $fecha, + ]; + $pieRepository = $this->container->get(Repository\Venta\Pie::class); + $pie = $pieRepository->create($pieData); + $pie = $pieRepository->save($pie); $ventaData = [ 'fecha' => $fecha, 'propietario' => $propietario->rut, 'propiedad' => $propiedad->id, 'fecha_ingreso' => new DateTimeImmutable($fecha)->add(new DateInterval('P3D'))->format('Y-m-d'), + 'pie' => $pie->id, ]; $ventaRepository = $this->container->get(Repository\Venta::class); $venta = $ventaRepository->create($ventaData); $venta = $ventaRepository->save($venta); + $bancoData = [ + 'nombre' => $faker->word, + ]; + $bancoRepository = $this->container->get(Repository\Contabilidad\Banco::class); + $banco = $bancoRepository->create($bancoData); + $banco = $bancoRepository->save($banco); $cuotaData = [ - 'venta' => $venta->id, + 'pie' => $pie->id, 'fecha' => '2022-01-01', 'valor' => 10000, + 'banco' => $banco->id, ]; $cuotaService = $this->container->get(Service\Venta\Cuota::class); $cuota = $cuotaService->add($cuotaData); $this->assertEquals(0.0, $cuota->pago->uf); - $queueService = $this->container->get(Service\Queue::class); $queueService->run(); $cuota = $cuotaService->getById($cuota->id);