Mostrar alertas en inicio
This commit is contained in:
@ -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];
|
||||
|
138
app/src/Controller/API/Ventas.php
Normal file
138
app/src/Controller/API/Ventas.php
Normal file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Ventas
|
||||
{
|
||||
use withJson;
|
||||
|
||||
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) {}
|
||||
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);
|
||||
}
|
||||
}
|
56
app/src/Controller/API/Ventas/Unidades.php
Normal file
56
app/src/Controller/API/Ventas/Unidades.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Unidades
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function disponibles(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, Repository\Proyecto\TipoUnidad $tipoUnidadRepository): ResponseInterface
|
||||
{
|
||||
$body = $request->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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Model;
|
||||
|
@ -11,7 +11,8 @@ class Proyecto extends Ideal\Repository
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected Inmobiliaria $inmobiliariaRepository,
|
||||
protected Direccion $direccionRepository
|
||||
protected Direccion $direccionRepository,
|
||||
protected Proyecto\Etapa $etapaRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
@ -71,13 +72,44 @@ class Proyecto extends Ideal\Repository
|
||||
}
|
||||
public function fetchAllActive(): array
|
||||
{
|
||||
$etapaProyecto = $this->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`";
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
@ -17,7 +17,7 @@ class TipoUnidad extends Ideal\Repository
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = new Implement\Repository\MapperParser(['descripcion', 'orden']);
|
||||
return $this->parseData(new Model\Venta\TipoUnidad(), $data, $map);
|
||||
return $this->parseData(new Model\Proyecto\TipoUnidad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user