Redis
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Direcciones;
|
||||
use Incoviba\Controller\API\Direcciones;
|
||||
|
||||
$app->group('/direcciones', function($app) {
|
||||
$app->group('/region/{region_id:[0-9]+}', function($app) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Provincias;
|
||||
use Incoviba\Controller\API\Provincias;
|
||||
|
||||
$app->group('/provincia/{provincia_id}', function($app) {
|
||||
$app->get('/comunas', [Provincias::class, 'comunas']);
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Regiones;
|
||||
|
||||
use Incoviba\Controller\API\Regiones;
|
||||
|
||||
//$app->group('/regiones', function($app) {});
|
||||
$app->group('/region/{region_id}', function($app) {
|
||||
|
@ -34,11 +34,11 @@
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.login === true) {
|
||||
@if(isset($redirect_uri))
|
||||
window.location = '{{$redirect_uri}}'
|
||||
@else
|
||||
window.location = '{{$urls->base}}'
|
||||
@endif
|
||||
@if(isset($redirect_uri))
|
||||
window.location = '{{$redirect_uri}}'
|
||||
@else
|
||||
window.location = '{{$urls->base}}'
|
||||
@endif
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
<form id="search_form" class="ui form" action="{{$urls->base}}/search" method="post">
|
||||
<div class="field">
|
||||
<div class="ui fluid input">
|
||||
<div class="ui fluid input" data-tooltip="Para buscar frases se deben encerrar entre comillas. ej, 'portal la viña' o "portal la viña"" data-position="bottom left">
|
||||
<input type="text" name="query" />
|
||||
</div>
|
||||
</div>
|
||||
@ -65,6 +65,9 @@
|
||||
unidad += '<i class="ban icon"></i>'
|
||||
}
|
||||
|
||||
const numberFormat = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
|
||||
const superficie = numberFormat.format(Math.round(this.unidad.proyecto_tipo_unidad.superficie * 100) / 100)
|
||||
|
||||
return $('<tr></tr>').append(
|
||||
$('<td></td>').append(
|
||||
$('<a></a>').attr('href', '{{$urls->base}}/proyecto/' + this.proyecto.id).html(this.proyecto.descripcion)
|
||||
@ -76,9 +79,9 @@
|
||||
).append(
|
||||
$('<td></td>').append(propietario)
|
||||
).append(
|
||||
$('<td></td>').addClass('right aligned').html(Math.round(this.unidad.proyecto_tipo_unidad.superficie * 100) / 100 + ' m²')
|
||||
$('<td></td>').addClass('right aligned').html(superficie + ' m²')
|
||||
).append(
|
||||
$('<td></td>').addClass('right aligned').html(this.unidad.precio)
|
||||
$('<td></td>').addClass('right aligned').html(numberFormat.format(this.unidad.precio))
|
||||
).append(
|
||||
$('<td></td>').html(fecha)
|
||||
).append(
|
||||
|
@ -9,6 +9,8 @@ return [
|
||||
return new Incoviba\Middleware\Authentication(
|
||||
$container->get(Psr\Http\Message\ResponseFactoryInterface::class),
|
||||
$container->get(Incoviba\Service\Login::class),
|
||||
$container->get(Psr\Log\LoggerInterface::class),
|
||||
$container->get(Incoviba\Common\Alias\View::class),
|
||||
implode('/', [$container->get('APP_URL'), 'login'])
|
||||
);
|
||||
}
|
||||
|
65
app/src/Controller/API/Direcciones.php
Normal file
65
app/src/Controller/API/Direcciones.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Direcciones
|
||||
{
|
||||
use withRedis, withJson;
|
||||
|
||||
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Repository\Provincia $provinciaRepository, Repository\Comuna $comunaRepository, int $region_id) : ResponseInterface
|
||||
{
|
||||
$output = ['total' => 0, 'comunas' => []];
|
||||
$redisKey = 'comunas';
|
||||
try {
|
||||
$output['comunas'] = $this->fetchRedis($redisService, $redisKey);
|
||||
$output['total'] = count($output['comunas']);
|
||||
} catch (EmptyRedis) {
|
||||
$provinciaKey = 'provincias';
|
||||
try {
|
||||
$temp_provincias = $this->fetchRedis($redisService, $provinciaKey);
|
||||
} catch (EmptyRedis) {
|
||||
$temp_provincias = $provinciaRepository->fetchByRegion($region_id);
|
||||
$this->saveRedis($redisService, $provinciaKey, $temp_provincias, 60 * 60 * 24 * 30);
|
||||
}
|
||||
$comunas = [];
|
||||
foreach($temp_provincias as $provincia) {
|
||||
$temp_comunas = $comunaRepository->fetchByProvincia($provincia->id);
|
||||
$comunas = array_merge($comunas, $temp_comunas);
|
||||
}
|
||||
usort($comunas, function(Model\Comuna $a, Model\Comuna $b) {
|
||||
return strcoll($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$output = ['comunas' => $comunas, 'total' => count($comunas)];
|
||||
$this->saveRedis($redisService, $redisKey, $comunas, 60 * 60 * 24 * 30);
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function findComunas(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Repository\Comuna $comunaRepository): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$output = ['input' => $json, 'total' => 0, 'comunas' => []];
|
||||
$redisKey = "comunas:direccion:{$json->direccion}";
|
||||
try {
|
||||
$output['comunas'] = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$comunas = $comunaRepository->fetchByDireccion($json->direccion);
|
||||
$output['comunas'] = $comunas;
|
||||
$output['total'] = count($comunas);
|
||||
$this->saveRedis($redisService, $redisKey, $comunas);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Service;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Money
|
||||
{
|
||||
@ -15,7 +16,8 @@ class Money
|
||||
|
||||
private int $time = 60 * 60 * 24 * 30;
|
||||
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, Service\Money $moneyService): ResponseInterface
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Money $moneyService): ResponseInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$output = [
|
||||
@ -42,7 +44,8 @@ class Money
|
||||
}
|
||||
|
||||
protected array $data;
|
||||
protected function getValue(Service\Redis $redisService, string $redisKey, Service\Money $moneyService, DateTimeInterface $date, string $provider): float
|
||||
protected function getValue(Service\Redis $redisService, string $redisKey, Service\Money $moneyService,
|
||||
DateTimeInterface $date, string $provider): float
|
||||
{
|
||||
if (isset($this->data[$date->format('Y-m-d')])) {
|
||||
return $this->data[$date->format('Y-m-d')];
|
||||
@ -85,7 +88,8 @@ class Money
|
||||
$output['uf'] = $ufs[$date->format('Y-m-d')];
|
||||
return $this->withJson($response, $output);
|
||||
}*/
|
||||
public function ipc(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, Service\Money $moneyService): ResponseInterface
|
||||
public function ipc(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Money $moneyService): ResponseInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$output = [
|
||||
|
39
app/src/Controller/API/Provincias.php
Normal file
39
app/src/Controller/API/Provincias.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Provincias
|
||||
{
|
||||
use withRedis, withJson;
|
||||
|
||||
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Repository\Comuna $comunaRepository, int $provincia_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'provincia_id' => $provincia_id,
|
||||
'comunas' => []
|
||||
];
|
||||
$redisKey = "comunas:provincia:{$provincia_id}";
|
||||
try {
|
||||
$output['comunas'] = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$comunas = $comunaRepository->fetchByProvincia($provincia_id);
|
||||
usort($comunas, function(Model\Comuna $a, Model\Comuna $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$output['comunas'] = $comunas;
|
||||
$this->saveRedis($redisService, $redisKey, $comunas, 60 * 60 * 24 * 30);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -1,39 +1,51 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
use withJson, withRedis;
|
||||
|
||||
public function list(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
public function list(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$output = ['total' => 0];
|
||||
$output = ['total' => 0, 'proyectos' => []];
|
||||
$redisKey = 'proyectos:activos';
|
||||
try {
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
$output['proyectos'] = $proyectos;
|
||||
$output['total'] = count($proyectos);
|
||||
} catch (EmptyResult) {}
|
||||
$output['proyectos'] = $this->fetchRedis($redisService, $redisKey);
|
||||
$output['total'] = count($output['proyectos']);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$output['proyectos'] = $proyectoRepository->fetchAllActive();
|
||||
$output['total'] = count($output['proyectos']);
|
||||
$this->saveRedis($redisService, $redisKey, $output['proyectos']);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function escriturando(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
public function escriturando(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Redis $redisService, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'total' => 0,
|
||||
'proyectos' => []
|
||||
];
|
||||
$output = ['total' => 0, 'proyectos' => []];
|
||||
$redisKey = 'proyectos:escriturando';
|
||||
try {
|
||||
$proyectos = $proyectoRepository->fetchAllEscriturando();
|
||||
$output['proyectos'] = $proyectos;
|
||||
$output['total'] = count($proyectos);
|
||||
} catch (EmptyResult) {}
|
||||
$output['proyectos'] = $this->fetchRedis($redisService, $redisKey);
|
||||
$output['total'] = count($output['proyectos']);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$output['proyectos'] = $proyectoRepository->fetchAllEscriturando();
|
||||
$output['total'] = count($output['proyectos']);
|
||||
$this->saveRedis($redisService, $redisKey, $output['proyectos']);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response,
|
||||
@ -41,7 +53,7 @@ class Proyectos
|
||||
int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
|
||||
$redisKey = "unidades-proyecto-{$proyecto_id}";
|
||||
$redisKey = "unidades:proyecto:{$proyecto_id}";
|
||||
try {
|
||||
$output = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
@ -66,21 +78,29 @@ class Proyectos
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function disponibles(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
|
||||
public function disponibles(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Redis $redisService, Repository\Venta\Unidad $unidadRepository,
|
||||
int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'unidades' => []
|
||||
];
|
||||
$redisKey = "unidades:disponibles:proyecto:{$proyecto_id}";
|
||||
try {
|
||||
$output['unidades'] = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
} catch (EmptyResult) {}
|
||||
$output['unidades'] = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$output['unidades'] = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
$this->saveRedis($redisService, $redisKey, $output['unidades']);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function superficies(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Proyecto $proyectoRepository, Repository\Venta $ventaRepository,
|
||||
Repository\Venta\Unidad $unidadRepository, Service\Redis $redisService,
|
||||
Service\Format $formatService, int $proyecto_id): ResponseInterface
|
||||
Repository\Venta $ventaRepository, Repository\Venta\Unidad $unidadRepository,
|
||||
Service\Redis $redisService, Service\Format $formatService,
|
||||
int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
@ -95,7 +115,7 @@ class Proyectos
|
||||
'por_vender' => '0m²'
|
||||
]
|
||||
];
|
||||
$redisKey = "superficices-proyecto-{$proyecto_id}";
|
||||
$redisKey = "superficices:proyecto:{$proyecto_id}";
|
||||
try {
|
||||
$output = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
|
@ -1,65 +1,98 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Proyectos;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API\emptyBody;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class EstadosProyectos
|
||||
{
|
||||
use withJson, emptyBody;
|
||||
public function byProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||
use withJson, emptyBody, withRedis;
|
||||
public function byProyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'estados' => []
|
||||
];
|
||||
$redisKey = "estados:proyecto:{$proyecto_id}";
|
||||
try {
|
||||
$output['estados'] = $estadoProyectoRepository->fetchByProyecto($proyecto_id);
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
$output['estados'] = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$output['estados'] = $estadoProyectoRepository->fetchByProyecto($proyecto_id);
|
||||
$this->saveRedis($redisService, $redisKey, $output['estados']);
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function currentByProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||
public function currentByProyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'estado' => null
|
||||
];
|
||||
$redisKey = "estado:proyecto:{$proyecto_id}";
|
||||
try {
|
||||
$output['estado'] = $estadoProyectoRepository->fetchCurrentByProyecto($proyecto_id);
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
$output['estado'] = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$output['estado'] = $estadoProyectoRepository->fetchCurrentByProyecto($proyecto_id);
|
||||
$this->saveRedis($redisService, $redisKey, $output['estado']);
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function firstByProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||
public function firstByProyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'estado' => null
|
||||
];
|
||||
$redisKey = "estado:proyecto:{$proyecto_id}:first";
|
||||
try {
|
||||
$output['estado'] = $estadoProyectoRepository->fetchFirstByProyecto($proyecto_id);
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
$output['estado'] = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$output['estado'] = $estadoProyectoRepository->fetchFirstByProyecto($proyecto_id);
|
||||
$this->saveRedis($redisService, $redisKey, $output['estado']);
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function recepcionByProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||
public function recepcionByProyecto(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Redis $redisService,
|
||||
Repository\Proyecto\EstadoProyecto $estadoProyectoRepository,
|
||||
int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'estado' => null
|
||||
];
|
||||
$redisKey = "recepcion:proyecto:{$proyecto_id}";
|
||||
try {
|
||||
$output['estado'] = $estadoProyectoRepository->fetchRecepcionByProyecto($proyecto_id);
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
$output['estado'] = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$output['estado'] = $estadoProyectoRepository->fetchRecepcionByProyecto($proyecto_id);
|
||||
$this->saveRedis($redisService, $redisKey, $output['estado']);
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
39
app/src/Controller/API/Regiones.php
Normal file
39
app/src/Controller/API/Regiones.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Regiones
|
||||
{
|
||||
use withRedis, withJson;
|
||||
|
||||
public function provincias(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Repository\Provincia $provinciaRepository, int $region_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'region_id' => $region_id,
|
||||
'provincias' => []
|
||||
];
|
||||
$redisKey = "provincias:region:{$region_id}";
|
||||
try {
|
||||
$output['provincias'] = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$provincias = $provinciaRepository->fetchByRegion($region_id);
|
||||
usort($provincias, function(Model\Provincia $a, Model\Provincia $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$output['provincias'] = $provincias;
|
||||
$this->saveRedis($redisService, $redisKey, $output['provincias'], 60 * 60 * 24 * 30);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -2,19 +2,21 @@
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class Ventas
|
||||
{
|
||||
use withJson, withRedis;
|
||||
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $service): ResponseInterface
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Repository\Proyecto $proyectoRepository, Repository\Venta $ventaRepository): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
@ -25,26 +27,50 @@ class Ventas
|
||||
],
|
||||
'total' => 0
|
||||
];
|
||||
$proyectosKey = "proyectos";
|
||||
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) {}
|
||||
$proyectos = $this->fetchRedis($redisService, $proyectosKey);
|
||||
} catch (EmptyRedis) {
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
$this->saveRedis($redisService, $proyectosKey, $proyectos);
|
||||
}
|
||||
$proyecto = array_values(array_filter($proyectos, function($proyecto) use ($proyecto_id) {return $proyecto->id === $proyecto_id;}))[0];
|
||||
$output['proyecto']['descripcion'] = $proyecto->descripcion;
|
||||
|
||||
$redisKey = "ventas:proyecto:{$proyecto_id}";
|
||||
try {
|
||||
$output['ventas'] = $this->fetchRedis($redisService, $redisKey);
|
||||
$output['total'] = count($output['ventas']);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$ventas = $ventaRepository->fetchActivaByProyecto($proyecto_id);
|
||||
$output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas);
|
||||
$output['total'] = count($ventas);
|
||||
$this->saveRedis($redisService, $redisKey, $output['ventas']);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
$redisKey = "venta:{$venta_id}";
|
||||
try {
|
||||
$venta = $service->getById($venta_id);
|
||||
$venta = $this->fetchRedis($redisService, $redisKey);
|
||||
$output = compact('venta');
|
||||
} catch (EmptyResult $exception) {
|
||||
$output = [
|
||||
'error' => [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
|
||||
]
|
||||
];
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$venta = $service->getById($venta_id);
|
||||
$output = compact('venta');
|
||||
$this->saveRedis($redisService, $redisKey, $venta);
|
||||
} catch (EmptyResult $exception) {
|
||||
$output = [
|
||||
'error' => [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
@ -54,7 +80,7 @@ class Ventas
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "promesas_por_firmar-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
$redisKey = "promesas:por_firmar:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}";
|
||||
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
@ -80,7 +106,7 @@ class Ventas
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "escrituras-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
$redisKey = "escrituras:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}";
|
||||
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
@ -127,18 +153,27 @@ class Ventas
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface
|
||||
public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
$output = ['total' => 0];
|
||||
$output = ['total' => 0, 'comentarios' => []];
|
||||
$redisKey = "comentarios:venta:{$venta_id}";
|
||||
try {
|
||||
$comentarios = $comentarioRepository->fetchByVenta($venta->id);
|
||||
$output['total'] = count($comentarios);
|
||||
$output['comentarios'] = $comentarios;
|
||||
} catch (EmptyResult) {}
|
||||
$output['comentarios'] = $this->fetchRedis($redisService, $redisKey);
|
||||
$output['total'] = count($output['comentarios']);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$comentarios = $comentarioRepository->fetchByVenta($venta->id);
|
||||
$output['total'] = count($comentarios);
|
||||
$output['comentarios'] = $comentarios;
|
||||
$this->saveRedis($redisService, $redisKey, $output['comentarios']);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Venta $ventaService): ResponseInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$output = [
|
||||
@ -146,28 +181,36 @@ class Ventas
|
||||
'errors' => []
|
||||
];
|
||||
try {
|
||||
$ventaService->add($data);
|
||||
$venta = $ventaService->add($data);
|
||||
$this->saveRedis($redisService, "venta:{$venta->id}", $venta);
|
||||
$output['status'] = true;
|
||||
} catch (\Exception $exception) {
|
||||
$output['errors'] = $exception;
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Unidad $unidadService, int $venta_id): ResponseInterface
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Venta\Unidad $unidadService, int $venta_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'venta_id' => $venta_id,
|
||||
'unidades' => []
|
||||
];
|
||||
$redisKey = "unidades:venta:{$venta_id}";
|
||||
try {
|
||||
$unidades = $unidadService->getByVenta($venta_id);
|
||||
$output['unidades'] = json_decode(json_encode($unidades));
|
||||
array_walk($output['unidades'], function($unidad, $index, $unidades) {
|
||||
$unidad->prorrateo = $unidades[$index]->prorrateo;
|
||||
$unidad->precios = $unidades[$index]->precios;
|
||||
$unidad->current_precio = $unidades[$index]->currentPrecio;
|
||||
}, $unidades);
|
||||
} catch (EmptyResult) {}
|
||||
$output['unidades'] = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$unidades = $unidadService->getByVenta($venta_id);
|
||||
$output['unidades'] = json_decode(json_encode($unidades));
|
||||
array_walk($output['unidades'], function($unidad, $index, $unidades) {
|
||||
$unidad->prorrateo = $unidades[$index]->prorrateo;
|
||||
$unidad->precios = $unidades[$index]->precios;
|
||||
$unidad->current_precio = $unidades[$index]->currentPrecio;
|
||||
}, $unidades);
|
||||
$this->saveRedis($redisService, $redisKey, $output['unidades']);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,74 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class Cierres
|
||||
{
|
||||
use withJson;
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Cierre $service): ResponseInterface
|
||||
use withJson, withRedis;
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Venta\Cierre $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = ['total' => 0];
|
||||
$output = ['total' => 0, 'cierres' => []];
|
||||
$redisKey = "cierres:proyecto:{$proyecto_id}";
|
||||
try {
|
||||
$cierres = $service->getByProyecto($proyecto_id);
|
||||
$output['cierres'] = $cierres;
|
||||
$output['total'] = count($cierres);
|
||||
} catch (EmptyResult) {}
|
||||
$output['cierres'] = $this->fetchRedis($redisService, $redisKey);
|
||||
$output['total'] = count($output['cierres']);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$cierres = $service->getByProyecto($proyecto_id);
|
||||
$output['cierres'] = $cierres;
|
||||
$this->saveRedis($redisService, $redisKey, $output['cierres']);
|
||||
$output['total'] = count($cierres);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function vigentes(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
public function vigentes(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
{
|
||||
$cierres = $cierreRepository->fetchDatosVigentes();
|
||||
$output = [];
|
||||
$estados = [
|
||||
'revisado' => 'pendientes',
|
||||
'rechazado' => 'rechazados',
|
||||
'aprobado' => 'pendientes',
|
||||
'vendido' => 'promesados',
|
||||
'abandonado' => 'rechazados',
|
||||
'promesado' => 'promesados',
|
||||
'resciliado' => 'rechazados'
|
||||
];
|
||||
foreach ($cierres as $row) {
|
||||
if (!isset($output[$row['Proyecto']])) {
|
||||
$output[$row['Proyecto']] = [
|
||||
'promesados' => 0,
|
||||
'pendientes' => 0,
|
||||
'rechazados' => 0,
|
||||
'total' => 0
|
||||
$output = ['cierres' => []];
|
||||
$redisKey = "cierres:vigentes";
|
||||
try {
|
||||
$output['cierres'] = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$cierres = $cierreRepository->fetchDatosVigentes();
|
||||
$estados = [
|
||||
'revisado' => 'pendientes',
|
||||
'rechazado' => 'rechazados',
|
||||
'aprobado' => 'pendientes',
|
||||
'vendido' => 'promesados',
|
||||
'abandonado' => 'rechazados',
|
||||
'promesado' => 'promesados',
|
||||
'resciliado' => 'rechazados'
|
||||
];
|
||||
}
|
||||
$estado = $estados[$row['Estado']];
|
||||
$output[$row['Proyecto']][$estado] += $row['Cantidad'];
|
||||
$output[$row['Proyecto']]['total'] += $row['Cantidad'];
|
||||
foreach ($cierres as $row) {
|
||||
if (!isset($output['cierres'][$row['Proyecto']])) {
|
||||
$output['cierres'][$row['Proyecto']] = [
|
||||
'promesados' => 0,
|
||||
'pendientes' => 0,
|
||||
'rechazados' => 0,
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
$estado = $estados[$row['Estado']];
|
||||
$output['cierres'][$row['Proyecto']][$estado] += $row['Cantidad'];
|
||||
$output['cierres'][$row['Proyecto']]['total'] += $row['Cantidad'];
|
||||
}
|
||||
$this->saveRedis($redisService, $redisKey, $output['cierres']);
|
||||
} catch (EmptyRedis) {}
|
||||
}
|
||||
return $this->withJson($response, ['cierres' => $output]);
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Incoviba\Controller\API\withRedis;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class Cuotas
|
||||
{
|
||||
use withJson, withRedis;
|
||||
public function hoy(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface
|
||||
public function hoy(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface
|
||||
{
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "cuotas_hoy-{$today->format('Y-m-d')}";
|
||||
$redisKey = "cuotas:hoy:{$today->format('Y-m-d')}";
|
||||
$output = [
|
||||
'cuotas' => 0
|
||||
];
|
||||
@ -32,10 +33,11 @@ class Cuotas
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function pendiente(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface
|
||||
public function pendiente(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface
|
||||
{
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "cuotas_pendientes-{$today->format('Y-m-d')}";
|
||||
$redisKey = "cuotas:pendientes:{$today->format('Y-m-d')}";
|
||||
$output = [
|
||||
'cuotas' => 0
|
||||
];
|
||||
@ -49,10 +51,12 @@ class Cuotas
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function porVencer(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService, Service\Format $formatService): ResponseInterface
|
||||
public function porVencer(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService,
|
||||
Service\Format $formatService): ResponseInterface
|
||||
{
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "cuotas_por_vencer-{$today->format('Y-m-d')}";
|
||||
$redisKey = "cuotas:por_vencer:{$today->format('Y-m-d')}";
|
||||
try {
|
||||
$output = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
|
@ -2,27 +2,28 @@
|
||||
namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API\emptyBody;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Service;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Controller\API\withRedis;
|
||||
use Incoviba\Controller\API\emptyBody;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
|
||||
class Facturacion
|
||||
{
|
||||
use withJson, withRedis, emptyBody;
|
||||
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, Service\Venta $ventaService, int $proyecto_id): ResponseInterface
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Venta $ventaService, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'ventas' => []
|
||||
];
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "ventas_facturacion-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
$redisKey = "ventas:facturacion:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}";
|
||||
try {
|
||||
$output['ventas'] = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
|
@ -1,36 +1,53 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API;
|
||||
use Incoviba\Service;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class Precios
|
||||
{
|
||||
use API\withJson, API\emptyBody;
|
||||
use API\withJson, API\emptyBody, \Incoviba\Controller\withRedis;
|
||||
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService): ResponseInterface
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Venta\Precio $precioService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = ['total' => 0];
|
||||
$output = ['total' => 0, 'precios' => []];
|
||||
$redisKey = "precios:proyecto:{$proyecto_id}";
|
||||
try {
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$output['precios'] = $precios;
|
||||
$output['total'] = count($precios);
|
||||
} catch (EmptyResult) {}
|
||||
$output['precios'] = $this->fetchRedis($redisService, $redisKey);
|
||||
$output['total'] = count($output['precios']);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$output['precios'] = $precios;
|
||||
$output['total'] = count($precios);
|
||||
$this->saveRedis($redisService, $redisKey, $output['precios']);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
{
|
||||
$redisKey = "precio:unidad:{$unidad_id}";
|
||||
try {
|
||||
$precio = $precioService->getVigenteByUnidad($unidad_id);
|
||||
$precio = $this->fetchRedis($redisService, $redisKey);
|
||||
return $this->withJson($response, compact('precio'));
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$precio = $precioService->getVigenteByUnidad($unidad_id);
|
||||
$this->saveRedis($redisService, $redisKey, $precio);
|
||||
return $this->withJson($response, compact('precio'));
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,14 @@ namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Controller\API\withRedis;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class Unidades
|
||||
{
|
||||
@ -22,7 +22,7 @@ class Unidades
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "unidades_disponibles-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
$redisKey = "unidades:disponibles:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}";
|
||||
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
|
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Direcciones
|
||||
{
|
||||
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Repository\Provincia $provinciaRepository, Repository\Comuna $comunaRepository, int $region_id) : ResponseInterface
|
||||
{
|
||||
$temp_provincias = $provinciaRepository->fetchByRegion($region_id);
|
||||
$comunas = [];
|
||||
foreach($temp_provincias as $provincia) {
|
||||
$temp_comunas = $comunaRepository->fetchByProvincia($provincia->id);
|
||||
$comunas = array_merge($comunas, $temp_comunas);
|
||||
}
|
||||
usort($comunas, function(Model\Comuna $a, Model\Comuna $b) {
|
||||
return strcoll($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$response->getBody()->write(json_encode(['comunas' => $comunas, 'total' => count($comunas)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function findComunas(ServerRequestInterface $request, ResponseInterface $response, Repository\Comuna $comunaRepository): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comunas = $comunaRepository->fetchByDireccion($json->direccion);
|
||||
$output['comunas'] = $comunas;
|
||||
$output['total'] = count($comunas);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -4,18 +4,42 @@ namespace Incoviba\Controller;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Inmobiliarias
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
|
||||
use withRedis;
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Redis $redisService, Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
|
||||
{
|
||||
$inmobiliarias = $inmobiliariaRepository->fetchAll();
|
||||
$redisKey = 'inmobiliarias';
|
||||
$inmobiliarias = [];
|
||||
try {
|
||||
$inmobiliarias = array_map(function($row) use ($inmobiliariaRepository) {
|
||||
return $inmobiliariaRepository->load((array) $row);
|
||||
}, $this->fetchRedis($redisService, $redisKey));
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$inmobiliarias = $inmobiliariaRepository->fetchAll();
|
||||
$this->saveRedis($redisService, $redisKey, $inmobiliarias);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $view->render($response, 'inmobiliarias.list', compact('inmobiliarias'));
|
||||
}
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Inmobiliaria $inmobiliariaRepository, int $inmobiliaria_rut): ResponseInterface
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Redis $redisService, Repository\Inmobiliaria $inmobiliariaRepository, int $inmobiliaria_rut): ResponseInterface
|
||||
{
|
||||
$inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut);
|
||||
$redisKey = "inmobiliaria:{$inmobiliaria_rut}";
|
||||
try {
|
||||
$inmobiliaria = $inmobiliariaRepository->load((array) $this->fetchRedis($redisService, $redisKey));
|
||||
} catch (EmptyResult) {
|
||||
$inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut);
|
||||
$this->saveRedis($redisService, $redisKey, $inmobiliaria);
|
||||
}
|
||||
return $view->render($response, 'inmobiliaria.show', compact('inmobiliaria'));
|
||||
}
|
||||
}
|
||||
|
@ -12,19 +12,10 @@ class Login
|
||||
{
|
||||
public function form(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service): ResponseInterface
|
||||
{
|
||||
$redirect_uri = $request->hasHeader('Referer') ? $request->getHeaderLine('Referer') : $view->get('urls')->base;
|
||||
if ($service->isIn()) {
|
||||
$redirect_uri = str_replace('/login', '', $redirect_uri);
|
||||
return $response->withStatus(301)->withHeader('Location', $redirect_uri);
|
||||
return $response->withStatus(301)->withHeader('Location', $view->get('urls')->base);
|
||||
}
|
||||
if ($request->hasHeader('X-Redirect-URI')) {
|
||||
$redirect_uri = $request->getHeaderLine('X-Redirect-URI');
|
||||
}
|
||||
$query = $request->getQueryParams();
|
||||
if (isset($query['url'])) {
|
||||
$redirect_uri = base64_decode(urldecode($query['url']));
|
||||
}
|
||||
return $view->render($response, 'login.form', compact('redirect_uri'));
|
||||
return $view->render($response, 'login.form');
|
||||
}
|
||||
public function login(ServerRequestInterface $request, ResponseInterface $response, Repository\User $userRepository, Service\Login $service): ResponseInterface
|
||||
{
|
||||
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Provincias
|
||||
{
|
||||
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Repository\Comuna $comunaRepository, int $provincia_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'provincia_id' => $provincia_id,
|
||||
'comunas' => []
|
||||
];
|
||||
try {
|
||||
$comunas = $comunaRepository->fetchByProvincia($provincia_id);
|
||||
usort($comunas, function(Model\Comuna $a, Model\Comuna $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$output['comunas'] = $comunas;
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -4,35 +4,62 @@ namespace Incoviba\Controller;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
use withRedis;
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$proyectos = $proyectoRepository->fetchAll();
|
||||
usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$proyectos = [];
|
||||
try {
|
||||
$proyectos = $proyectoRepository->fetchAll();
|
||||
usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
} catch (EmptyResult) {}
|
||||
return $view->render($response, 'proyectos.list', compact('proyectos'));
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Proyecto $proyectoRepository, Repository\Venta\Unidad $unidadRepository): ResponseInterface
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Redis $redisService, Repository\Proyecto $proyectoRepository,
|
||||
Repository\Venta\Unidad $unidadRepository): ResponseInterface
|
||||
{
|
||||
$proyectos = $proyectoRepository->fetchAll();
|
||||
$proyectos = array_filter($proyectos, function(Model\Proyecto $proyecto) use ($unidadRepository) {
|
||||
$unidades = $unidadRepository->fetchByProyecto($proyecto->id);
|
||||
return count($unidades) > 0;
|
||||
});
|
||||
usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$proyectos = [];
|
||||
$redisKey = "proyectos:con_unidades";
|
||||
try {
|
||||
$proyectos = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$proyectos = $proyectoRepository->fetchAll();
|
||||
$proyectos = array_filter($proyectos, function(Model\Proyecto $proyecto) use ($unidadRepository) {
|
||||
$unidades = $unidadRepository->fetchByProyecto($proyecto->id);
|
||||
return count($unidades) > 0;
|
||||
});
|
||||
usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$this->saveRedis($redisService, $redisKey, $proyectos);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $view->render($response, 'proyectos.unidades', compact('proyectos'));
|
||||
}
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService, int $proyecto_id): ResponseInterface
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Redis $redisService, Service\Proyecto $proyectoService,
|
||||
Repository\Proyecto $proyectoRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$proyecto = $proyectoService->getById($proyecto_id);
|
||||
$redisKey = "proyecto:{$proyecto_id}";
|
||||
try {
|
||||
$proyecto = $proyectoService->getById($proyectoRepository->load((array) $this->fetchRedis($redisService, $redisKey)));
|
||||
} catch (EmptyRedis) {
|
||||
$proyecto = $proyectoService->getById($proyecto_id);
|
||||
$this->saveRedis($redisService, $redisKey, $proyecto);
|
||||
}
|
||||
return $view->render($response, 'proyectos.show', compact('proyecto'));
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Regiones
|
||||
{
|
||||
public function provincias(ServerRequestInterface $request, ResponseInterface $response, Repository\Provincia $provinciaRepository, int $region_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'region_id' => $region_id,
|
||||
'provincias' => []
|
||||
];
|
||||
try {
|
||||
$provincias = $provinciaRepository->fetchByRegion($region_id);
|
||||
usort($provincias, function(Model\Provincia $a, Model\Provincia $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$output['provincias'] = $provincias;
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -1,28 +1,42 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use MongoDB\Driver\Server;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Ventas
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService): ResponseInterface
|
||||
use withRedis;
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Redis $redisService, Service\Proyecto $proyectoService,
|
||||
Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
|
||||
$redisKey = "proyectos:vendibles";
|
||||
try {
|
||||
$proyectos = $proyectoService->process($proyectoRepository->load((array) $this->fetchRedis($redisService, $redisKey)));
|
||||
} catch (EmptyRedis) {
|
||||
$proyectos = array_map(function(Model\Proyecto $proyecto) {
|
||||
return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];
|
||||
}, $proyectoService->getVendibles());
|
||||
$this->saveRedis($redisService, $redisKey, $proyectos);
|
||||
}
|
||||
return $view->render($response, 'ventas.list', compact('proyectos'));
|
||||
}
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
return $view->render($response, 'ventas.show', compact('venta'));
|
||||
}
|
||||
public function showUnidad(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, string $proyecto_nombre, int $unidad_descripcion): ResponseInterface
|
||||
public function showUnidad(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Venta $service, string $proyecto_nombre, int $unidad_descripcion): ResponseInterface
|
||||
{
|
||||
$proyecto_nombre = urldecode($proyecto_nombre);
|
||||
$venta = $service->getByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Service;
|
@ -1,26 +1,33 @@
|
||||
<?php
|
||||
namespace Incoviba\Middleware;
|
||||
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Psr\Http\Message\ResponseFactoryInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Incoviba\Service;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Authentication
|
||||
{
|
||||
public function __construct(protected ResponseFactoryInterface $responseFactory, protected Service\Login $service, protected string $login_url) {}
|
||||
public function __construct(
|
||||
protected ResponseFactoryInterface $responseFactory,
|
||||
protected Service\Login $service,
|
||||
protected LoggerInterface $logger,
|
||||
protected View $view,
|
||||
protected string $login_url) {}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if ($this->service->isIn() or $this->isValid($request)) {
|
||||
return $handler->handle($request);
|
||||
}
|
||||
$response = $this->responseFactory->createResponse(301, 'Not logged in');
|
||||
$uri = urlencode(base64_encode((string) $request->getUri()));
|
||||
return $response->withHeader('Location', implode('?', [$this->login_url, "url={$uri}"]))
|
||||
$this->logger->notice("Not logged in.");
|
||||
$response = $this->responseFactory->createResponse(301, 'Not logged in')
|
||||
->withHeader('Referer', (string) $request->getUri())
|
||||
->withHeader('X-Redirected-URI', (string) $request->getUri());
|
||||
return $this->view->render($response, 'login.form', ['redirect_uri' => (string) $request->getUri()]);
|
||||
}
|
||||
|
||||
protected function isValid(ServerRequestInterface $request): bool
|
||||
|
@ -76,7 +76,7 @@ class Proyecto extends Ideal\Repository
|
||||
->select($this->columns())
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinTerreno())
|
||||
->where("name = ?");
|
||||
->where("descripcion = ?");
|
||||
return $this->fetchOne($query, [$name]);
|
||||
}
|
||||
public function fetchAllActive(): array
|
||||
|
@ -16,7 +16,16 @@ class Subsidio extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Model\Venta\Subsidio
|
||||
{
|
||||
$map = new Implement\Repository\MapperParser(['pago', 'subsidio']);
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('pago', (new Implement\Repository\Mapper())
|
||||
->setProperty('ahorro')
|
||||
->setFunction(function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}))
|
||||
->register('subsidio', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->pagoRepository->fetchById($data['subsidio']);
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Subsidio(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Venta\Subsidio
|
||||
|
@ -19,11 +19,15 @@ class Proyecto
|
||||
{
|
||||
return $this->proyectoRepository->fetchAllEscriturando();
|
||||
}
|
||||
public function getById(int $venta_id): Model\Proyecto
|
||||
public function getById(int $proyecto_id): Model\Proyecto
|
||||
{
|
||||
return $this->process($this->proyectoRepository->fetchById($venta_id));
|
||||
return $this->process($this->proyectoRepository->fetchById($proyecto_id));
|
||||
}
|
||||
protected function process(Model\Proyecto $proyecto): Model\Proyecto
|
||||
public function getByName(string $name): Model\Proyecto
|
||||
{
|
||||
return $this->process($this->proyectoRepository->fetchByName($name));
|
||||
}
|
||||
public function process(Model\Proyecto $proyecto): Model\Proyecto
|
||||
{
|
||||
$proyecto->addFactory('estados', (new Implement\Repository\Factory())
|
||||
->setCallable([$this->estadoProyecto, 'fetchByProyecto'])
|
||||
|
@ -2,12 +2,18 @@
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
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\Proyecto\TipoUnidad $tipoUnidadRepository) {}
|
||||
public function __construct(
|
||||
protected Proyecto $proyectoService,
|
||||
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
|
||||
{
|
||||
@ -39,7 +45,12 @@ class Search
|
||||
}
|
||||
protected function find(string $query, string $tipo): array
|
||||
{
|
||||
$queries = explode(' ', $query);
|
||||
preg_match_all('/["\']([\s\w]+)["\']|(\w+)/i', $query, $matches, PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL);
|
||||
$queries = array_map(function($match) {
|
||||
array_shift($match);
|
||||
$valid = array_filter($match, function($line) {return $line !== null;});
|
||||
return implode(' ', $valid);
|
||||
}, $matches);
|
||||
$tiposUnidades = $this->getTiposUnidades();
|
||||
$results = [];
|
||||
foreach ($queries as $q) {
|
||||
@ -113,7 +124,8 @@ class Search
|
||||
protected function findProyecto(string $query): array
|
||||
{
|
||||
try {
|
||||
return $this->ventaService->getByProyecto($query);
|
||||
$proyecto = $this->proyectoService->getByName($query);
|
||||
return $this->ventaService->getByProyecto($proyecto->id);
|
||||
} catch (EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ class Venta
|
||||
return $venta;
|
||||
}
|
||||
|
||||
public function add(array $data): void
|
||||
public function add(array $data): Model\Venta
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha_venta']);
|
||||
$data['uf'] = $this->moneyService->getUF($fecha);
|
||||
@ -103,6 +103,8 @@ class Venta
|
||||
'fecha' => $venta->fecha->format('Y-m-d')
|
||||
]);
|
||||
$this->estadoVentaRepository->save($estado);
|
||||
|
||||
return $venta;
|
||||
}
|
||||
protected function addPropietario(array $data): Model\Venta\Propietario
|
||||
{
|
||||
|
Reference in New Issue
Block a user