diff --git a/app/resources/views/ventas/precios/list.blade.php b/app/resources/views/ventas/precios/list.blade.php
index 5820b22..5b4ae22 100644
--- a/app/resources/views/ventas/precios/list.blade.php
+++ b/app/resources/views/ventas/precios/list.blade.php
@@ -75,48 +75,46 @@
@push('page_scripts')
@endpush
diff --git a/app/src/Controller/API/Proyectos.php b/app/src/Controller/API/Proyectos.php
index d547dae..5ed2152 100644
--- a/app/src/Controller/API/Proyectos.php
+++ b/app/src/Controller/API/Proyectos.php
@@ -21,6 +21,19 @@ class Proyectos
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
+ public function escriturando(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
+ {
+ $output = [
+ 'total' => 0,
+ 'proyectos' => []
+ ];
+ try {
+ $proyectos = $proyectoRepository->fetchAllEscriturando();
+ $output['proyectos'] = $proyectos;
+ $output['total'] = count($proyectos);
+ } catch (EmptyResult) {}
+ return $this->withJson($response, $output);
+ }
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
{
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
diff --git a/app/src/Controller/API/Ventas.php b/app/src/Controller/API/Ventas.php
new file mode 100644
index 0000000..bdfc853
--- /dev/null
+++ b/app/src/Controller/API/Ventas.php
@@ -0,0 +1,138 @@
+getBody();
+ $json = json_decode($body->getContents());
+ $proyecto_id = $json->proyecto_id;
+ $output = [
+ 'proyecto' => [
+ 'id' => $proyecto_id
+ ],
+ 'total' => 0
+ ];
+ try {
+ $ventas = $service->fetchActivaByProyecto($proyecto_id);
+ $output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas);
+ $output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion;
+ $output['total'] = count($ventas);
+ } catch (EmptyResult) {}
+ return $this->withJson($response, $output);
+ }
+ public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface
+ {
+ try {
+ $venta = $service->getById($venta_id);
+ $output = compact('venta');
+ } catch (EmptyResult $exception) {
+ $output = [
+ 'error' => [
+ 'code' => $exception->getCode(),
+ 'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
+ ]
+ ];
+ }
+ return $this->withJson($response, $output);
+ }
+ public function porFirmar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface
+ {
+ $body = $request->getBody();
+ $json = json_decode($body->getContents());
+ $proyecto_id = $json->proyecto_id;
+ $output = [
+ 'proyecto_id' => $proyecto_id,
+ 'promesas' => 0
+ ];
+ try {
+ $ventas = $ventaService->getByProyecto($proyecto_id);
+ $promesas = array_filter($ventas, function(Model\Venta $venta) {
+ return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'vigente';
+ });
+ $output['promesas'] = count($promesas);
+ } catch (EmptyResult) {}
+ return $this->withJson($response, $output);
+ }
+ public function escrituras(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Service\Venta\Pago $pagoService): ResponseInterface
+ {
+ $body = $request->getBody();
+ $json = json_decode($body->getContents());
+ $proyecto_id = $json->proyecto_id;
+ $output = [
+ 'proyecto_id' => $proyecto_id,
+ 'escrituras' => [
+ 'firmar' => 0,
+ 'pagar' => 0,
+ 'abonar' => 0
+ ]
+ ];
+ try {
+ $ventas = $ventaService->getEscriturasByProyecto($proyecto_id);
+ $porFirmar = array_filter($ventas, function(Model\Venta $venta) {
+ return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'escriturando';
+ });
+ $output['escrituras']['firmar'] = count($porFirmar);
+ unset($porFirmar);
+ $escrituras = array_filter($ventas, function(Model\Venta $venta) {
+ return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'firmado por inmobiliaria';
+ });
+ unset($ventas);
+ $porPagar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) {
+ $pagos = $pagoService->getByVenta($venta->id);
+ $porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) {
+ return $pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado';
+ });
+ return count($porPagar) > 0;
+ });
+ $output['escrituras']['pagar'] = count($porPagar);
+ unset($porPagar);
+ $porAbonar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) {
+ $pagos = $pagoService->getByVenta($venta->id);
+ $porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) {
+ return $pago->currentEstado->tipoEstadoPago->descripcion === 'depositado';
+ });
+ return count($porPagar) > 0;
+ });
+ $output['escrituras']['abonar'] = count($porAbonar);
+ unset($porAbonar);
+ } catch (EmptyResult) {}
+ return $this->withJson($response, $output);
+ }
+ public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface
+ {
+ $venta = $service->getById($venta_id);
+ $output = ['total' => 0];
+ try {
+ $comentarios = $comentarioRepository->fetchByVenta($venta->id);
+ $output['total'] = count($comentarios);
+ $output['comentarios'] = $comentarios;
+ } catch (EmptyResult) {}
+ return $this->withJson($response, $output);
+ }
+ public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface
+ {
+ $data = $request->getParsedBody();
+ $output = [
+ 'status' => false,
+ 'errors' => []
+ ];
+ try {
+ $ventaService->add($data);
+ $output['status'] = true;
+ } catch (\Exception $exception) {
+ $output['errors'] = $exception;
+ }
+ return $this->withJson($response, $output);
+ }
+}
diff --git a/app/src/Controller/API/Ventas/Unidades.php b/app/src/Controller/API/Ventas/Unidades.php
new file mode 100644
index 0000000..f04deeb
--- /dev/null
+++ b/app/src/Controller/API/Ventas/Unidades.php
@@ -0,0 +1,56 @@
+getBody();
+ $json = json_decode($body->getContents());
+ $proyecto_id = $json->proyecto_id;
+ $output = [
+ 'proyecto_id' => $proyecto_id,
+ 'unidades' => [
+ 'total' => [
+ 'departamentos' => 0,
+ 'estacionamientos' => 0,
+ 'bodegas' => 0,
+ ],
+ 'departamentos' => 0,
+ 'estacionamientos' => 0,
+ 'bodegas' => 0,
+ ]
+ ];
+ try {
+ $totalUnidades = $unidadRepository->fetchByProyecto($proyecto_id);
+ $unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
+
+ $tiposUnidades = $tipoUnidadRepository->fetchAll();
+ foreach ($tiposUnidades as $tipoUnidad) {
+ $tempUnidades = array_filter($totalUnidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) {
+ return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id;
+ });
+ if (count($tempUnidades) > 0) {
+ $output['unidades']['total']["{$tipoUnidad->descripcion}s"] = count($tempUnidades);
+ }
+ $tempUnidades = array_filter($unidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) {
+ return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id;
+ });
+ if (count($tempUnidades) === 0) {
+ continue;
+ }
+ $output['unidades']["{$tipoUnidad->descripcion}s"] = count($tempUnidades);
+ }
+ } catch (EmptyResult) {}
+ return $this->withJson($response, $output);
+ }
+}
diff --git a/app/src/Controller/Ventas.php b/app/src/Controller/Ventas.php
index 3b54065..22583ba 100644
--- a/app/src/Controller/Ventas.php
+++ b/app/src/Controller/Ventas.php
@@ -28,39 +28,6 @@ class Ventas
$venta = $service->getByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);
return $view->render($response, 'ventas.show', compact('venta'));
}
- public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $service): ResponseInterface
- {
- $body = $request->getBody();
- $json = json_decode($body->getContents());
- $proyecto_id = $json->proyecto_id;
- $output = [
- 'proyecto' => [
- 'id' => $proyecto_id
- ],
- 'total' => 0
- ];
- try {
- $ventas = $service->fetchActivaByProyecto($proyecto_id);
- $output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas);
- $output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion;
- $output['total'] = count($ventas);
- } catch (EmptyResult) {}
- $response->getBody()->write(json_encode($output));
- return $response->withHeader('Content-Type', 'application/json');
- }
- public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface
- {
- try {
- $venta = $service->getById($venta_id);
- $response->getBody()->write(json_encode(compact('venta')));
- } catch (EmptyResult $exception) {
- $response->getBody()->write(json_encode(['error' => [
- 'code' => $exception->getCode(),
- 'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
- ]]));
- }
- return $response->withHeader('Content-Type', 'application/json');
- }
public function edit(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface
{
$venta = $service->getById($venta_id);
@@ -90,18 +57,6 @@ class Ventas
}
return $view->render($response, 'ventas.propiedades.edit', compact('propiedad', 'proyecto', 'tiposUnidades', 'unidades', 'venta_id'));
}
- public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface
- {
- $venta = $service->getById($venta_id);
- $output = ['total' => 0];
- try {
- $comentarios = $comentarioRepository->fetchByVenta($venta->id);
- $output['total'] = count($comentarios);
- $output['comentarios'] = $comentarios;
- } catch (EmptyResult) {}
- $response->getBody()->write(json_encode($output));
- return $response->withHeader('Content-Type', 'application/json');
- }
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Region $regionRepository, Repository\Proyecto $proyectoRepository): ResponseInterface
{
$regiones = $regionRepository->fetchAll();
@@ -111,22 +66,6 @@ class Ventas
$proyectos = $proyectoRepository->fetchAllActive();
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
}
- public function doAdd(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface
- {
- $data = $request->getParsedBody();
- $output = [
- 'status' => false,
- 'errors' => []
- ];
- try {
- $ventaService->add($data);
- $output['status'] = true;
- } catch (\Exception $exception) {
- $output['errors'] = $exception;
- }
- $response->getBody()->write(json_encode($output));
- return $response->withHeader('Content-Type', 'application/json');
- }
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, View $view, int $venta_id): ResponseInterface
{
$venta = $ventaService->getById($venta_id);
diff --git a/app/src/Model/Proyecto/ProyectoTipoUnidad.php b/app/src/Model/Proyecto/ProyectoTipoUnidad.php
index e05f9d9..8c7a6bf 100644
--- a/app/src/Model/Proyecto/ProyectoTipoUnidad.php
+++ b/app/src/Model/Proyecto/ProyectoTipoUnidad.php
@@ -7,7 +7,7 @@ use Incoviba\Model;
class ProyectoTipoUnidad extends Ideal\Model
{
public Model\Proyecto $proyecto;
- public Model\Venta\TipoUnidad $tipoUnidad;
+ public Model\Proyecto\TipoUnidad $tipoUnidad;
public string $nombre;
public string $abreviacion;
public float $util;
diff --git a/app/src/Model/Venta/TipoUnidad.php b/app/src/Model/Proyecto/TipoUnidad.php
similarity index 87%
rename from app/src/Model/Venta/TipoUnidad.php
rename to app/src/Model/Proyecto/TipoUnidad.php
index 4c1af89..7f7954a 100644
--- a/app/src/Model/Venta/TipoUnidad.php
+++ b/app/src/Model/Proyecto/TipoUnidad.php
@@ -1,5 +1,5 @@
etapaRepository->fetchByDescripcion('Proyecto');
+ $etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado');
$query = "SELECT a.*
FROM `{$this->getTable()}` a
- JOIN (SELECT e1.* FROM `estado_proyecto` e1 JOIN (SELECT MAX(`id`) AS 'id', `proyecto` FROM `estado_proyecto` GROUP BY `proyecto`) e0 ON e0.`id` = e1.`id`) ep ON ep.`proyecto` = a.`id`
- JOIN `tipo_estado_proyecto` tep ON tep.`id` = ep.`estado`
- JOIN `etapa_proyecto` et ON et.`id` = tep.`etapa`
-WHERE et.`orden` BETWEEN 4 AND 8
+ {$this->joinEstado()}
+WHERE et.`orden` BETWEEN {$etapaProyecto->orden} AND ({$etapaTerminado->orden} - 1)
ORDER BY a.`descripcion`";
return $this->fetchMany($query);
}
+ public function fetchAllEscriturando(): array
+ {
+ $etapaRecepcion = $this->etapaRepository->fetchByDescripcion('Recepción');
+ $etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado');
+ $query = "SELECT a.*
+FROM `{$this->getTable()}` a
+ {$this->joinEstado()}
+WHERE et.`orden` BETWEEN {$etapaRecepcion->orden} AND ({$etapaTerminado->orden} - 1)
+ORDER BY a.`descripcion`";
+ return $this->fetchMany($query);
+ }
+
+ protected function joinEstado(): string
+ {
+ return "JOIN (
+ SELECT e2.*
+ FROM `estado_proyecto` e2
+ JOIN (
+ SELECT MAX(e1.`id`) AS 'id', e1.`proyecto`
+ FROM `estado_proyecto` e1
+ JOIN (
+ SELECT MAX(`id`) AS 'id', `proyecto`, `fecha`
+ FROM `estado_proyecto`
+ GROUP BY `proyecto`, `fecha`
+ ) e0 ON e1.`id` = e0.`id`
+ GROUP BY `proyecto`
+ ) e01 ON e01.`id` = e2.`id`
+ ) ep ON ep.`proyecto` = a.`id`
+ JOIN `tipo_estado_proyecto` tep ON tep.`id` = ep.`estado`
+ JOIN `etapa_proyecto` et ON et.`id` = tep.`etapa`";
+ }
}
diff --git a/app/src/Repository/Proyecto/Etapa.php b/app/src/Repository/Proyecto/Etapa.php
index e81a1a6..4ab3bbb 100644
--- a/app/src/Repository/Proyecto/Etapa.php
+++ b/app/src/Repository/Proyecto/Etapa.php
@@ -28,4 +28,10 @@ class Etapa extends Ideal\Repository
{
return $this->update($model, ['descripcion', 'orden'], $new_data);
}
+
+ public function fetchByDescripcion(string $descripcion): Model\Proyecto\Etapa
+ {
+ $query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
+ return $this->fetchOne($query, [$descripcion]);
+ }
}
diff --git a/app/src/Repository/Proyecto/ProyectoTipoUnidad.php b/app/src/Repository/Proyecto/ProyectoTipoUnidad.php
index 4beb4ac..737f767 100644
--- a/app/src/Repository/Proyecto/ProyectoTipoUnidad.php
+++ b/app/src/Repository/Proyecto/ProyectoTipoUnidad.php
@@ -9,7 +9,7 @@ use Incoviba\Repository;
class ProyectoTipoUnidad extends Ideal\Repository
{
- public function __construct(Define\Connection $connection, protected Repository\Proyecto $proyectoRepository, protected Repository\Venta\TipoUnidad $tipoUnidadRepository)
+ public function __construct(Define\Connection $connection, protected Repository\Proyecto $proyectoRepository, protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository)
{
parent::__construct($connection);
$this->setTable('proyecto_tipo_unidad');
diff --git a/app/src/Repository/Venta/TipoUnidad.php b/app/src/Repository/Proyecto/TipoUnidad.php
similarity index 87%
rename from app/src/Repository/Venta/TipoUnidad.php
rename to app/src/Repository/Proyecto/TipoUnidad.php
index 035a9a2..1290c4f 100644
--- a/app/src/Repository/Venta/TipoUnidad.php
+++ b/app/src/Repository/Proyecto/TipoUnidad.php
@@ -1,8 +1,8 @@
parseData(new Model\Venta\TipoUnidad(), $data, $map);
+ return $this->parseData(new Model\Proyecto\TipoUnidad(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
diff --git a/app/src/Repository/Venta.php b/app/src/Repository/Venta.php
index 3944586..c8f28ef 100644
--- a/app/src/Repository/Venta.php
+++ b/app/src/Repository/Venta.php
@@ -220,4 +220,17 @@ FROM `{$this->getTable()}` a
WHERE CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?";
return $this->fetchMany($query, [$propietario]);
}
+ public function fetchEscriturasByProyecto(int $proyecto_id): array
+ {
+ $query = "SELECT DISTINCT a.*
+FROM `{$this->getTable()}` a
+ JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
+ JOIN `unidad` ON `unidad`.`id` = pu.`unidad`
+ JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`id`
+ JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
+ JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
+WHERE ptu.`proyecto` = ? AND tev.`descripcion` IN ('firmado por inmobiliaria', 'escriturando')
+GROUP BY a.`id`";
+ return $this->fetchMany($query, [$proyecto_id]);
+ }
}
diff --git a/app/src/Repository/Venta/Pago.php b/app/src/Repository/Venta/Pago.php
index 04e380b..451789e 100644
--- a/app/src/Repository/Venta/Pago.php
+++ b/app/src/Repository/Venta/Pago.php
@@ -60,4 +60,44 @@ class Pago extends Ideal\Repository
{
return $this->update($model, ['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'], $new_data);
}
+
+ public function fetchByVenta(int $venta_id): array
+ {
+ $query = "SELECT a.*
+FROM (
+ SELECT a.*, venta.id AS venta_id, 'cuota' AS fuente
+ FROM pago a
+ JOIN cuota ON cuota.pago = a.id
+ JOIN venta ON venta.pie = cuota.pie
+ UNION ALL
+ SELECT a.*, venta.id AS venta_id, 'reajuste' AS fuente
+ FROM pago a
+ JOIN pie ON pie.reajuste = a.id
+ JOIN venta ON venta.pie = pie.id
+ UNION ALL
+ SELECT a.*, venta.id AS venta_id, 'credito' AS fuente
+ FROM pago a
+ JOIN credito ON credito.pago = a.id
+ JOIN venta ON venta.credito = credito.id
+ UNION ALL
+ SELECT a.*, venta.id AS venta_id, 'escritura' AS fuente
+ FROM pago a
+ JOIN escritura ON escritura.pago = a.id
+ JOIN venta ON venta.escritura = escritura.id
+ UNION ALL
+ SELECT a.*, venta.id AS venta_id, 'subsidio' AS fuente
+ FROM pago a
+ JOIN subsidio ON subsidio.subsidio = a.id
+ JOIN venta ON venta.subsidio = subsidio.id
+ UNION ALL
+ SELECT a.*, venta.id AS venta_id, 'ahorro' AS fuente
+ FROM pago a
+ JOIN subsidio ON subsidio.pago = a.id
+ JOIN venta ON venta.subsidio = subsidio.id
+ ) a
+ JOIN (SELECT e1.* FROM estado_pago e1 JOIN (SELECT MAX(id) AS id, pago FROM estado_pago GROUP BY pago) e0 ON e0.id = e1.id) ep ON ep.pago = a.id
+ JOIN tipo_estado_pago tep ON tep.id = ep.estado
+WHERE venta_id = ?";
+ return $this->fetchMany($query, [$venta_id]);
+ }
}
diff --git a/app/src/Service/Search.php b/app/src/Service/Search.php
index 82421e8..3a704bd 100644
--- a/app/src/Service/Search.php
+++ b/app/src/Service/Search.php
@@ -2,12 +2,12 @@
namespace Incoviba\Service;
use Incoviba\Common\Implement\Exception\EmptyResult;
-use Incoviba\Repository;
use Incoviba\Model;
+use Incoviba\Repository;
class Search
{
- public function __construct(protected Venta $ventaService, protected Repository\Venta $ventaRepository, protected Repository\Venta\Unidad $unidadRepository, protected Repository\Venta\TipoUnidad $tipoUnidadRepository) {}
+ public function __construct(protected Venta $ventaService, protected Repository\Venta $ventaRepository, protected Repository\Venta\Unidad $unidadRepository, protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository) {}
public function query(string $query, string $tipo): array
{
@@ -127,7 +127,7 @@ class Search
protected function getTiposUnidades(): array
{
if (!isset($this->tipos)) {
- $this->tipos = array_map(function(Model\Venta\TipoUnidad $tipoUnidad) {
+ $this->tipos = array_map(function(Model\Proyecto\TipoUnidad $tipoUnidad) {
return $tipoUnidad->descripcion;
}, $this->tipoUnidadRepository->fetchAll());
}
diff --git a/app/src/Service/Venta.php b/app/src/Service/Venta.php
index 93fdd1d..01215b7 100644
--- a/app/src/Service/Venta.php
+++ b/app/src/Service/Venta.php
@@ -28,18 +28,12 @@ class Venta
public function getByProyecto(int $proyecto_id): array
{
$ventas = $this->ventaRepository->fetchByProyecto($proyecto_id);
- foreach ($ventas as &$venta) {
- $venta = $this->process($venta);
- }
- return $ventas;
+ return array_map([$this, 'process'], $ventas);
}
public function getActivaByProyecto(int $proyecto_id): array
{
$ventas = $this->ventaRepository->fetchActivaByProyecto($proyecto_id);
- foreach ($ventas as &$venta) {
- $venta = $this->process($venta);
- }
- return $ventas;
+ return array_map([$this, 'process'], $ventas);
}
public function getByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta
{
@@ -49,26 +43,22 @@ class Venta
public function getByUnidad(string $unidad, string $tipo): array
{
$ventas = $this->ventaRepository->fetchByUnidad($unidad, $tipo);
- foreach ($ventas as &$venta) {
- $venta = $this->process($venta);
- }
- return $ventas;
+ return array_map([$this, 'process'], $ventas);
}
public function getByPropietario(string $propietario): array
{
$ventas = $this->ventaRepository->fetchByPropietario($propietario);
- foreach ($ventas as &$venta) {
- $venta = $this->process($venta);
- }
- return $ventas;
+ return array_map([$this, 'process'], $ventas);
}
public function getByPrecio(string $precio): array
{
$ventas = $this->ventaRepository->fetchByPrecio($precio);
- foreach ($ventas as &$venta) {
- $venta = $this->process($venta);
- }
- return $ventas;
+ return array_map([$this, 'process'], $ventas);
+ }
+ public function getEscriturasByProyecto(int $proyecto_id): array
+ {
+ $ventas = $this->ventaRepository->fetchEscriturasByProyecto($proyecto_id);
+ return array_map([$this, 'process'], $ventas);
}
protected function process(Model\Venta $venta): Model\Venta
diff --git a/app/src/Service/Venta/Pago.php b/app/src/Service/Venta/Pago.php
index cff2779..3f8d161 100644
--- a/app/src/Service/Venta/Pago.php
+++ b/app/src/Service/Venta/Pago.php
@@ -69,15 +69,12 @@ class Pago
public function getById(int $pago_id): Model\Venta\Pago
{
$pago = $this->pagoRepository->fetchById($pago_id);
- $pago->estados = $this->estadoPagoRepository->fetchByPago($pago_id);
- $pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago_id);
- if (($pago->uf === null or $pago->uf === 0.0) and $pago->fecha < new DateTimeImmutable()) {
- $pago->uf = $this->moneyService->getUF($pago->fecha);
- if ($pago->uf !== 0.0) {
- $this->pagoRepository->edit($pago, ['uf' => $pago->uf]);
- }
- }
- return $pago;
+ return $this->process($pago);
+ }
+
+ public function getByVenta(int $venta_id): array
+ {
+ return array_map([$this, 'process'], $this->pagoRepository->fetchByVenta($venta_id));
}
public function getPendientes(): array
@@ -121,4 +118,17 @@ class Pago
$pago->currentEstado = $estado;
return $pago;
}
+
+ protected function process($pago): Model\Venta\Pago
+ {
+ $pago->estados = $this->estadoPagoRepository->fetchByPago($pago->id);
+ $pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago->id);
+ if (($pago->uf === null or $pago->uf === 0.0) and $pago->fecha < new DateTimeImmutable()) {
+ $pago->uf = $this->moneyService->getUF($pago->fecha);
+ if ($pago->uf !== 0.0) {
+ $this->pagoRepository->edit($pago, ['uf' => $pago->uf]);
+ }
+ }
+ return $pago;
+ }
}
diff --git a/docker-compose.yml b/docker-compose.yml
index 88027bf..09ec208 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -41,6 +41,8 @@ services:
volumes:
- dbdata:/var/lib/mysql
- ./incoviba.sql.gz:/docker-entrypoint-initdb.d/incoviba.sql.gz
+ ports:
+ - "33060:3306"
networks:
- default
- adminer_network