Redis
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
use Incoviba\Controller\Direcciones;
|
use Incoviba\Controller\API\Direcciones;
|
||||||
|
|
||||||
$app->group('/direcciones', function($app) {
|
$app->group('/direcciones', function($app) {
|
||||||
$app->group('/region/{region_id:[0-9]+}', function($app) {
|
$app->group('/region/{region_id:[0-9]+}', function($app) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
use Incoviba\Controller\Provincias;
|
use Incoviba\Controller\API\Provincias;
|
||||||
|
|
||||||
$app->group('/provincia/{provincia_id}', function($app) {
|
$app->group('/provincia/{provincia_id}', function($app) {
|
||||||
$app->get('/comunas', [Provincias::class, 'comunas']);
|
$app->get('/comunas', [Provincias::class, 'comunas']);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
use Incoviba\Controller\Regiones;
|
|
||||||
|
use Incoviba\Controller\API\Regiones;
|
||||||
|
|
||||||
//$app->group('/regiones', function($app) {});
|
//$app->group('/regiones', function($app) {});
|
||||||
$app->group('/region/{region_id}', function($app) {
|
$app->group('/region/{region_id}', function($app) {
|
||||||
|
@ -34,11 +34,11 @@
|
|||||||
}
|
}
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
if (data.login === true) {
|
if (data.login === true) {
|
||||||
@if(isset($redirect_uri))
|
@if(isset($redirect_uri))
|
||||||
window.location = '{{$redirect_uri}}'
|
window.location = '{{$redirect_uri}}'
|
||||||
@else
|
@else
|
||||||
window.location = '{{$urls->base}}'
|
window.location = '{{$urls->base}}'
|
||||||
@endif
|
@endif
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<form id="search_form" class="ui form" action="{{$urls->base}}/search" method="post">
|
<form id="search_form" class="ui form" action="{{$urls->base}}/search" method="post">
|
||||||
<div class="field">
|
<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" />
|
<input type="text" name="query" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -65,6 +65,9 @@
|
|||||||
unidad += '<i class="ban icon"></i>'
|
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(
|
return $('<tr></tr>').append(
|
||||||
$('<td></td>').append(
|
$('<td></td>').append(
|
||||||
$('<a></a>').attr('href', '{{$urls->base}}/proyecto/' + this.proyecto.id).html(this.proyecto.descripcion)
|
$('<a></a>').attr('href', '{{$urls->base}}/proyecto/' + this.proyecto.id).html(this.proyecto.descripcion)
|
||||||
@ -76,9 +79,9 @@
|
|||||||
).append(
|
).append(
|
||||||
$('<td></td>').append(propietario)
|
$('<td></td>').append(propietario)
|
||||||
).append(
|
).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(
|
).append(
|
||||||
$('<td></td>').addClass('right aligned').html(this.unidad.precio)
|
$('<td></td>').addClass('right aligned').html(numberFormat.format(this.unidad.precio))
|
||||||
).append(
|
).append(
|
||||||
$('<td></td>').html(fecha)
|
$('<td></td>').html(fecha)
|
||||||
).append(
|
).append(
|
||||||
|
@ -9,6 +9,8 @@ return [
|
|||||||
return new Incoviba\Middleware\Authentication(
|
return new Incoviba\Middleware\Authentication(
|
||||||
$container->get(Psr\Http\Message\ResponseFactoryInterface::class),
|
$container->get(Psr\Http\Message\ResponseFactoryInterface::class),
|
||||||
$container->get(Incoviba\Service\Login::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'])
|
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
|
<?php
|
||||||
namespace Incoviba\Controller\API;
|
namespace Incoviba\Controller\API;
|
||||||
|
|
||||||
use DateTimeInterface;
|
|
||||||
use DateTimeImmutable;
|
|
||||||
use DateInterval;
|
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\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
|
||||||
use Incoviba\Service;
|
|
||||||
|
|
||||||
class Money
|
class Money
|
||||||
{
|
{
|
||||||
@ -15,7 +16,8 @@ class Money
|
|||||||
|
|
||||||
private int $time = 60 * 60 * 24 * 30;
|
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();
|
$data = $request->getParsedBody();
|
||||||
$output = [
|
$output = [
|
||||||
@ -42,7 +44,8 @@ class Money
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected array $data;
|
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')])) {
|
if (isset($this->data[$date->format('Y-m-d')])) {
|
||||||
return $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')];
|
$output['uf'] = $ufs[$date->format('Y-m-d')];
|
||||||
return $this->withJson($response, $output);
|
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();
|
$data = $request->getParsedBody();
|
||||||
$output = [
|
$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
|
<?php
|
||||||
namespace Incoviba\Controller\API;
|
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\EmptyRedis;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Controller\withRedis;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Proyectos
|
class Proyectos
|
||||||
{
|
{
|
||||||
use withJson, withRedis;
|
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 {
|
try {
|
||||||
$proyectos = $proyectoRepository->fetchAllActive();
|
$output['proyectos'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
$output['proyectos'] = $proyectos;
|
$output['total'] = count($output['proyectos']);
|
||||||
$output['total'] = count($proyectos);
|
} catch (EmptyRedis) {
|
||||||
} catch (EmptyResult) {}
|
try {
|
||||||
|
$output['proyectos'] = $proyectoRepository->fetchAllActive();
|
||||||
|
$output['total'] = count($output['proyectos']);
|
||||||
|
$this->saveRedis($redisService, $redisKey, $output['proyectos']);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
}
|
||||||
return $this->withJson($response, $output);
|
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 = [
|
$output = ['total' => 0, 'proyectos' => []];
|
||||||
'total' => 0,
|
$redisKey = 'proyectos:escriturando';
|
||||||
'proyectos' => []
|
|
||||||
];
|
|
||||||
try {
|
try {
|
||||||
$proyectos = $proyectoRepository->fetchAllEscriturando();
|
$output['proyectos'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
$output['proyectos'] = $proyectos;
|
$output['total'] = count($output['proyectos']);
|
||||||
$output['total'] = count($proyectos);
|
} catch (EmptyRedis) {
|
||||||
} catch (EmptyResult) {}
|
try {
|
||||||
|
$output['proyectos'] = $proyectoRepository->fetchAllEscriturando();
|
||||||
|
$output['total'] = count($output['proyectos']);
|
||||||
|
$this->saveRedis($redisService, $redisKey, $output['proyectos']);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response,
|
public function unidades(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
@ -41,7 +53,7 @@ class Proyectos
|
|||||||
int $proyecto_id): ResponseInterface
|
int $proyecto_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
|
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
|
||||||
$redisKey = "unidades-proyecto-{$proyecto_id}";
|
$redisKey = "unidades:proyecto:{$proyecto_id}";
|
||||||
try {
|
try {
|
||||||
$output = $this->fetchRedis($redisService, $redisKey);
|
$output = $this->fetchRedis($redisService, $redisKey);
|
||||||
} catch (EmptyRedis) {
|
} catch (EmptyRedis) {
|
||||||
@ -66,21 +78,29 @@ class Proyectos
|
|||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
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 = [
|
$output = [
|
||||||
'proyecto_id' => $proyecto_id,
|
'proyecto_id' => $proyecto_id,
|
||||||
'unidades' => []
|
'unidades' => []
|
||||||
];
|
];
|
||||||
|
$redisKey = "unidades:disponibles:proyecto:{$proyecto_id}";
|
||||||
try {
|
try {
|
||||||
$output['unidades'] = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
$output['unidades'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
} catch (EmptyResult) {}
|
} catch (EmptyRedis) {
|
||||||
|
try {
|
||||||
|
$output['unidades'] = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||||
|
$this->saveRedis($redisService, $redisKey, $output['unidades']);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
public function superficies(ServerRequestInterface $request, ResponseInterface $response,
|
public function superficies(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Repository\Proyecto $proyectoRepository, Repository\Venta $ventaRepository,
|
Repository\Venta $ventaRepository, Repository\Venta\Unidad $unidadRepository,
|
||||||
Repository\Venta\Unidad $unidadRepository, Service\Redis $redisService,
|
Service\Redis $redisService, Service\Format $formatService,
|
||||||
Service\Format $formatService, int $proyecto_id): ResponseInterface
|
int $proyecto_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$output = [
|
$output = [
|
||||||
'proyecto_id' => $proyecto_id,
|
'proyecto_id' => $proyecto_id,
|
||||||
@ -95,7 +115,7 @@ class Proyectos
|
|||||||
'por_vender' => '0m²'
|
'por_vender' => '0m²'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
$redisKey = "superficices-proyecto-{$proyecto_id}";
|
$redisKey = "superficices:proyecto:{$proyecto_id}";
|
||||||
try {
|
try {
|
||||||
$output = $this->fetchRedis($redisService, $redisKey);
|
$output = $this->fetchRedis($redisService, $redisKey);
|
||||||
} catch (EmptyRedis) {
|
} catch (EmptyRedis) {
|
||||||
|
@ -1,65 +1,98 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller\API\Proyectos;
|
namespace Incoviba\Controller\API\Proyectos;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Controller\API\emptyBody;
|
use Incoviba\Controller\API\emptyBody;
|
||||||
use Incoviba\Controller\API\withJson;
|
use Incoviba\Controller\API\withJson;
|
||||||
|
use Incoviba\Controller\withRedis;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class EstadosProyectos
|
class EstadosProyectos
|
||||||
{
|
{
|
||||||
use withJson, emptyBody;
|
use withJson, emptyBody, withRedis;
|
||||||
public function byProyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
public function byProyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||||
|
Repository\Proyecto\EstadoProyecto $estadoProyectoRepository, int $proyecto_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$output = [
|
$output = [
|
||||||
'proyecto_id' => $proyecto_id,
|
'proyecto_id' => $proyecto_id,
|
||||||
'estados' => []
|
'estados' => []
|
||||||
];
|
];
|
||||||
|
$redisKey = "estados:proyecto:{$proyecto_id}";
|
||||||
try {
|
try {
|
||||||
$output['estados'] = $estadoProyectoRepository->fetchByProyecto($proyecto_id);
|
$output['estados'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
} catch (EmptyResult) {
|
} catch (EmptyRedis) {
|
||||||
return $this->emptyBody($response);
|
try {
|
||||||
|
$output['estados'] = $estadoProyectoRepository->fetchByProyecto($proyecto_id);
|
||||||
|
$this->saveRedis($redisService, $redisKey, $output['estados']);
|
||||||
|
} catch (EmptyResult) {
|
||||||
|
return $this->emptyBody($response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
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 = [
|
$output = [
|
||||||
'proyecto_id' => $proyecto_id,
|
'proyecto_id' => $proyecto_id,
|
||||||
'estado' => null
|
'estado' => null
|
||||||
];
|
];
|
||||||
|
$redisKey = "estado:proyecto:{$proyecto_id}";
|
||||||
try {
|
try {
|
||||||
$output['estado'] = $estadoProyectoRepository->fetchCurrentByProyecto($proyecto_id);
|
$output['estado'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
} catch (EmptyResult) {
|
} catch (EmptyRedis) {
|
||||||
return $this->emptyBody($response);
|
try {
|
||||||
|
$output['estado'] = $estadoProyectoRepository->fetchCurrentByProyecto($proyecto_id);
|
||||||
|
$this->saveRedis($redisService, $redisKey, $output['estado']);
|
||||||
|
} catch (EmptyResult) {
|
||||||
|
return $this->emptyBody($response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
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 = [
|
$output = [
|
||||||
'proyecto_id' => $proyecto_id,
|
'proyecto_id' => $proyecto_id,
|
||||||
'estado' => null
|
'estado' => null
|
||||||
];
|
];
|
||||||
|
$redisKey = "estado:proyecto:{$proyecto_id}:first";
|
||||||
try {
|
try {
|
||||||
$output['estado'] = $estadoProyectoRepository->fetchFirstByProyecto($proyecto_id);
|
$output['estado'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
} catch (EmptyResult) {
|
} catch (EmptyRedis) {
|
||||||
return $this->emptyBody($response);
|
try {
|
||||||
|
$output['estado'] = $estadoProyectoRepository->fetchFirstByProyecto($proyecto_id);
|
||||||
|
$this->saveRedis($redisService, $redisKey, $output['estado']);
|
||||||
|
} catch (EmptyResult) {
|
||||||
|
return $this->emptyBody($response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
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 = [
|
$output = [
|
||||||
'proyecto_id' => $proyecto_id,
|
'proyecto_id' => $proyecto_id,
|
||||||
'estado' => null
|
'estado' => null
|
||||||
];
|
];
|
||||||
|
$redisKey = "recepcion:proyecto:{$proyecto_id}";
|
||||||
try {
|
try {
|
||||||
$output['estado'] = $estadoProyectoRepository->fetchRecepcionByProyecto($proyecto_id);
|
$output['estado'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
} catch (EmptyResult) {
|
} catch (EmptyRedis) {
|
||||||
return $this->emptyBody($response);
|
try {
|
||||||
|
$output['estado'] = $estadoProyectoRepository->fetchRecepcionByProyecto($proyecto_id);
|
||||||
|
$this->saveRedis($redisService, $redisKey, $output['estado']);
|
||||||
|
} catch (EmptyResult) {
|
||||||
|
return $this->emptyBody($response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
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;
|
namespace Incoviba\Controller\API;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Incoviba\Controller\withRedis;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Ventas
|
class Ventas
|
||||||
{
|
{
|
||||||
use withJson, withRedis;
|
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();
|
$body = $request->getBody();
|
||||||
$json = json_decode($body->getContents());
|
$json = json_decode($body->getContents());
|
||||||
@ -25,26 +27,50 @@ class Ventas
|
|||||||
],
|
],
|
||||||
'total' => 0
|
'total' => 0
|
||||||
];
|
];
|
||||||
|
$proyectosKey = "proyectos";
|
||||||
try {
|
try {
|
||||||
$ventas = $service->fetchActivaByProyecto($proyecto_id);
|
$proyectos = $this->fetchRedis($redisService, $proyectosKey);
|
||||||
$output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas);
|
} catch (EmptyRedis) {
|
||||||
$output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion;
|
$proyectos = $proyectoRepository->fetchAllActive();
|
||||||
$output['total'] = count($ventas);
|
$this->saveRedis($redisService, $proyectosKey, $proyectos);
|
||||||
} catch (EmptyResult) {}
|
}
|
||||||
|
$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);
|
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 {
|
try {
|
||||||
$venta = $service->getById($venta_id);
|
$venta = $this->fetchRedis($redisService, $redisKey);
|
||||||
$output = compact('venta');
|
$output = compact('venta');
|
||||||
} catch (EmptyResult $exception) {
|
} catch (EmptyRedis) {
|
||||||
$output = [
|
try {
|
||||||
'error' => [
|
$venta = $service->getById($venta_id);
|
||||||
'code' => $exception->getCode(),
|
$output = compact('venta');
|
||||||
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
|
$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);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
@ -54,7 +80,7 @@ class Ventas
|
|||||||
$json = json_decode($body->getContents());
|
$json = json_decode($body->getContents());
|
||||||
$proyecto_id = $json->proyecto_id;
|
$proyecto_id = $json->proyecto_id;
|
||||||
$today = new DateTimeImmutable();
|
$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 = [
|
$output = [
|
||||||
'proyecto_id' => $proyecto_id,
|
'proyecto_id' => $proyecto_id,
|
||||||
@ -80,7 +106,7 @@ class Ventas
|
|||||||
$json = json_decode($body->getContents());
|
$json = json_decode($body->getContents());
|
||||||
$proyecto_id = $json->proyecto_id;
|
$proyecto_id = $json->proyecto_id;
|
||||||
$today = new DateTimeImmutable();
|
$today = new DateTimeImmutable();
|
||||||
$redisKey = "escrituras-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
|
$redisKey = "escrituras:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}";
|
||||||
|
|
||||||
$output = [
|
$output = [
|
||||||
'proyecto_id' => $proyecto_id,
|
'proyecto_id' => $proyecto_id,
|
||||||
@ -127,18 +153,27 @@ class Ventas
|
|||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
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);
|
$venta = $service->getById($venta_id);
|
||||||
$output = ['total' => 0];
|
$output = ['total' => 0, 'comentarios' => []];
|
||||||
|
$redisKey = "comentarios:venta:{$venta_id}";
|
||||||
try {
|
try {
|
||||||
$comentarios = $comentarioRepository->fetchByVenta($venta->id);
|
$output['comentarios'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
$output['total'] = count($comentarios);
|
$output['total'] = count($output['comentarios']);
|
||||||
$output['comentarios'] = $comentarios;
|
} catch (EmptyRedis) {
|
||||||
} catch (EmptyResult) {}
|
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);
|
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();
|
$data = $request->getParsedBody();
|
||||||
$output = [
|
$output = [
|
||||||
@ -146,28 +181,36 @@ class Ventas
|
|||||||
'errors' => []
|
'errors' => []
|
||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
$ventaService->add($data);
|
$venta = $ventaService->add($data);
|
||||||
|
$this->saveRedis($redisService, "venta:{$venta->id}", $venta);
|
||||||
$output['status'] = true;
|
$output['status'] = true;
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$output['errors'] = $exception;
|
$output['errors'] = $exception;
|
||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
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 = [
|
$output = [
|
||||||
'venta_id' => $venta_id,
|
'venta_id' => $venta_id,
|
||||||
'unidades' => []
|
'unidades' => []
|
||||||
];
|
];
|
||||||
|
$redisKey = "unidades:venta:{$venta_id}";
|
||||||
try {
|
try {
|
||||||
$unidades = $unidadService->getByVenta($venta_id);
|
$output['unidades'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
$output['unidades'] = json_decode(json_encode($unidades));
|
} catch (EmptyRedis) {
|
||||||
array_walk($output['unidades'], function($unidad, $index, $unidades) {
|
try {
|
||||||
$unidad->prorrateo = $unidades[$index]->prorrateo;
|
$unidades = $unidadService->getByVenta($venta_id);
|
||||||
$unidad->precios = $unidades[$index]->precios;
|
$output['unidades'] = json_decode(json_encode($unidades));
|
||||||
$unidad->current_precio = $unidades[$index]->currentPrecio;
|
array_walk($output['unidades'], function($unidad, $index, $unidades) {
|
||||||
}, $unidades);
|
$unidad->prorrateo = $unidades[$index]->prorrateo;
|
||||||
} catch (EmptyResult) {}
|
$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);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,55 +1,74 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller\API\Ventas;
|
namespace Incoviba\Controller\API\Ventas;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Controller\API\withJson;
|
use Incoviba\Controller\API\withJson;
|
||||||
|
use Incoviba\Controller\withRedis;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Cierres
|
class Cierres
|
||||||
{
|
{
|
||||||
use withJson;
|
use withJson, withRedis;
|
||||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Cierre $service): ResponseInterface
|
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||||
|
Service\Venta\Cierre $service): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getBody();
|
$body = $request->getBody();
|
||||||
$json = json_decode($body->getContents());
|
$json = json_decode($body->getContents());
|
||||||
$proyecto_id = $json->proyecto_id;
|
$proyecto_id = $json->proyecto_id;
|
||||||
$output = ['total' => 0];
|
$output = ['total' => 0, 'cierres' => []];
|
||||||
|
$redisKey = "cierres:proyecto:{$proyecto_id}";
|
||||||
try {
|
try {
|
||||||
$cierres = $service->getByProyecto($proyecto_id);
|
$output['cierres'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
$output['cierres'] = $cierres;
|
$output['total'] = count($output['cierres']);
|
||||||
$output['total'] = count($cierres);
|
} catch (EmptyRedis) {
|
||||||
} catch (EmptyResult) {}
|
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);
|
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 = ['cierres' => []];
|
||||||
$output = [];
|
$redisKey = "cierres:vigentes";
|
||||||
$estados = [
|
try {
|
||||||
'revisado' => 'pendientes',
|
$output['cierres'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
'rechazado' => 'rechazados',
|
} catch (EmptyRedis) {
|
||||||
'aprobado' => 'pendientes',
|
try {
|
||||||
'vendido' => 'promesados',
|
$cierres = $cierreRepository->fetchDatosVigentes();
|
||||||
'abandonado' => 'rechazados',
|
$estados = [
|
||||||
'promesado' => 'promesados',
|
'revisado' => 'pendientes',
|
||||||
'resciliado' => 'rechazados'
|
'rechazado' => 'rechazados',
|
||||||
];
|
'aprobado' => 'pendientes',
|
||||||
foreach ($cierres as $row) {
|
'vendido' => 'promesados',
|
||||||
if (!isset($output[$row['Proyecto']])) {
|
'abandonado' => 'rechazados',
|
||||||
$output[$row['Proyecto']] = [
|
'promesado' => 'promesados',
|
||||||
'promesados' => 0,
|
'resciliado' => 'rechazados'
|
||||||
'pendientes' => 0,
|
|
||||||
'rechazados' => 0,
|
|
||||||
'total' => 0
|
|
||||||
];
|
];
|
||||||
}
|
foreach ($cierres as $row) {
|
||||||
$estado = $estados[$row['Estado']];
|
if (!isset($output['cierres'][$row['Proyecto']])) {
|
||||||
$output[$row['Proyecto']][$estado] += $row['Cantidad'];
|
$output['cierres'][$row['Proyecto']] = [
|
||||||
$output[$row['Proyecto']]['total'] += $row['Cantidad'];
|
'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
|
<?php
|
||||||
namespace Incoviba\Controller\API\Ventas;
|
namespace Incoviba\Controller\API\Ventas;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use Incoviba\Controller\API\withRedis;
|
use DateTimeImmutable;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Controller\API\withJson;
|
use Incoviba\Controller\API\withJson;
|
||||||
|
use Incoviba\Controller\withRedis;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Cuotas
|
class Cuotas
|
||||||
{
|
{
|
||||||
use withJson, withRedis;
|
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();
|
$today = new DateTimeImmutable();
|
||||||
$redisKey = "cuotas_hoy-{$today->format('Y-m-d')}";
|
$redisKey = "cuotas:hoy:{$today->format('Y-m-d')}";
|
||||||
$output = [
|
$output = [
|
||||||
'cuotas' => 0
|
'cuotas' => 0
|
||||||
];
|
];
|
||||||
@ -32,10 +33,11 @@ class Cuotas
|
|||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
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();
|
$today = new DateTimeImmutable();
|
||||||
$redisKey = "cuotas_pendientes-{$today->format('Y-m-d')}";
|
$redisKey = "cuotas:pendientes:{$today->format('Y-m-d')}";
|
||||||
$output = [
|
$output = [
|
||||||
'cuotas' => 0
|
'cuotas' => 0
|
||||||
];
|
];
|
||||||
@ -49,10 +51,12 @@ class Cuotas
|
|||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
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();
|
$today = new DateTimeImmutable();
|
||||||
$redisKey = "cuotas_por_vencer-{$today->format('Y-m-d')}";
|
$redisKey = "cuotas:por_vencer:{$today->format('Y-m-d')}";
|
||||||
try {
|
try {
|
||||||
$output = $this->fetchRedis($redisService, $redisKey);
|
$output = $this->fetchRedis($redisService, $redisKey);
|
||||||
} catch (EmptyRedis) {
|
} catch (EmptyRedis) {
|
||||||
|
@ -2,27 +2,28 @@
|
|||||||
namespace Incoviba\Controller\API\Ventas;
|
namespace Incoviba\Controller\API\Ventas;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
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\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
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
|
class Facturacion
|
||||||
{
|
{
|
||||||
use withJson, withRedis, emptyBody;
|
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 = [
|
$output = [
|
||||||
'proyecto_id' => $proyecto_id,
|
'proyecto_id' => $proyecto_id,
|
||||||
'ventas' => []
|
'ventas' => []
|
||||||
];
|
];
|
||||||
$today = new DateTimeImmutable();
|
$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 {
|
try {
|
||||||
$output['ventas'] = $this->fetchRedis($redisService, $redisKey);
|
$output['ventas'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
} catch (EmptyRedis) {
|
} catch (EmptyRedis) {
|
||||||
|
@ -1,36 +1,53 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller\API\Ventas;
|
namespace Incoviba\Controller\API\Ventas;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Controller\API;
|
use Incoviba\Controller\API;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Precios
|
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();
|
$body = $request->getBody();
|
||||||
$json = json_decode($body->getContents());
|
$json = json_decode($body->getContents());
|
||||||
$proyecto_id = $json->proyecto_id;
|
$proyecto_id = $json->proyecto_id;
|
||||||
$output = ['total' => 0];
|
$output = ['total' => 0, 'precios' => []];
|
||||||
|
$redisKey = "precios:proyecto:{$proyecto_id}";
|
||||||
try {
|
try {
|
||||||
$precios = $precioService->getByProyecto($proyecto_id);
|
$output['precios'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
$output['precios'] = $precios;
|
$output['total'] = count($output['precios']);
|
||||||
$output['total'] = count($precios);
|
} catch (EmptyRedis) {
|
||||||
} catch (EmptyResult) {}
|
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);
|
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 {
|
try {
|
||||||
$precio = $precioService->getVigenteByUnidad($unidad_id);
|
$precio = $this->fetchRedis($redisService, $redisKey);
|
||||||
return $this->withJson($response, compact('precio'));
|
return $this->withJson($response, compact('precio'));
|
||||||
} catch (EmptyResult) {
|
} catch (EmptyRedis) {
|
||||||
return $this->emptyBody($response);
|
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 DateTimeImmutable;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Controller\API\withJson;
|
use Incoviba\Controller\API\withJson;
|
||||||
use Incoviba\Controller\API\withRedis;
|
use Incoviba\Controller\withRedis;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Unidades
|
class Unidades
|
||||||
{
|
{
|
||||||
@ -22,7 +22,7 @@ class Unidades
|
|||||||
$json = json_decode($body->getContents());
|
$json = json_decode($body->getContents());
|
||||||
$proyecto_id = $json->proyecto_id;
|
$proyecto_id = $json->proyecto_id;
|
||||||
$today = new DateTimeImmutable();
|
$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 = [
|
$output = [
|
||||||
'proyecto_id' => $proyecto_id,
|
'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\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Incoviba\Common\Alias\View;
|
use Incoviba\Common\Alias\View;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Service;
|
||||||
|
|
||||||
class Inmobiliarias
|
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'));
|
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'));
|
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
|
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()) {
|
if ($service->isIn()) {
|
||||||
$redirect_uri = str_replace('/login', '', $redirect_uri);
|
return $response->withStatus(301)->withHeader('Location', $view->get('urls')->base);
|
||||||
return $response->withStatus(301)->withHeader('Location', $redirect_uri);
|
|
||||||
}
|
}
|
||||||
if ($request->hasHeader('X-Redirect-URI')) {
|
return $view->render($response, 'login.form');
|
||||||
$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'));
|
|
||||||
}
|
}
|
||||||
public function login(ServerRequestInterface $request, ResponseInterface $response, Repository\User $userRepository, Service\Login $service): ResponseInterface
|
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\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Incoviba\Common\Alias\View;
|
use Incoviba\Common\Alias\View;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
|
||||||
class Proyectos
|
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();
|
$proyectos = [];
|
||||||
usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) {
|
try {
|
||||||
return strcmp($a->descripcion, $b->descripcion);
|
$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'));
|
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 = [];
|
||||||
$proyectos = array_filter($proyectos, function(Model\Proyecto $proyecto) use ($unidadRepository) {
|
$redisKey = "proyectos:con_unidades";
|
||||||
$unidades = $unidadRepository->fetchByProyecto($proyecto->id);
|
try {
|
||||||
return count($unidades) > 0;
|
$proyectos = $this->fetchRedis($redisService, $redisKey);
|
||||||
});
|
} catch (EmptyRedis) {
|
||||||
usort($proyectos, function(Model\Proyecto $a, Model\Proyecto $b) {
|
try {
|
||||||
return strcmp($a->descripcion, $b->descripcion);
|
$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'));
|
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'));
|
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
|
<?php
|
||||||
namespace Incoviba\Controller;
|
namespace Incoviba\Controller;
|
||||||
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
|
||||||
use MongoDB\Driver\Server;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Incoviba\Common\Alias\View;
|
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\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Service;
|
||||||
|
|
||||||
class Ventas
|
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'));
|
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);
|
$venta = $service->getById($venta_id);
|
||||||
return $view->render($response, 'ventas.show', compact('venta'));
|
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);
|
$proyecto_nombre = urldecode($proyecto_nombre);
|
||||||
$venta = $service->getByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);
|
$venta = $service->getByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller\API;
|
namespace Incoviba\Controller;
|
||||||
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
@ -1,26 +1,33 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Middleware;
|
namespace Incoviba\Middleware;
|
||||||
|
|
||||||
|
use Incoviba\Common\Alias\View;
|
||||||
use Psr\Http\Message\ResponseFactoryInterface;
|
use Psr\Http\Message\ResponseFactoryInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Server\RequestHandlerInterface;
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Authentication
|
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
|
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||||
{
|
{
|
||||||
if ($this->service->isIn() or $this->isValid($request)) {
|
if ($this->service->isIn() or $this->isValid($request)) {
|
||||||
return $handler->handle($request);
|
return $handler->handle($request);
|
||||||
}
|
}
|
||||||
$response = $this->responseFactory->createResponse(301, 'Not logged in');
|
$this->logger->notice("Not logged in.");
|
||||||
$uri = urlencode(base64_encode((string) $request->getUri()));
|
$response = $this->responseFactory->createResponse(301, 'Not logged in')
|
||||||
return $response->withHeader('Location', implode('?', [$this->login_url, "url={$uri}"]))
|
|
||||||
->withHeader('Referer', (string) $request->getUri())
|
->withHeader('Referer', (string) $request->getUri())
|
||||||
->withHeader('X-Redirected-URI', (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
|
protected function isValid(ServerRequestInterface $request): bool
|
||||||
|
@ -76,7 +76,7 @@ class Proyecto extends Ideal\Repository
|
|||||||
->select($this->columns())
|
->select($this->columns())
|
||||||
->from("{$this->getTable()} a")
|
->from("{$this->getTable()} a")
|
||||||
->joined($this->joinTerreno())
|
->joined($this->joinTerreno())
|
||||||
->where("name = ?");
|
->where("descripcion = ?");
|
||||||
return $this->fetchOne($query, [$name]);
|
return $this->fetchOne($query, [$name]);
|
||||||
}
|
}
|
||||||
public function fetchAllActive(): array
|
public function fetchAllActive(): array
|
||||||
|
@ -16,7 +16,16 @@ class Subsidio extends Ideal\Repository
|
|||||||
|
|
||||||
public function create(?array $data = null): Model\Venta\Subsidio
|
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);
|
return $this->parseData(new Model\Venta\Subsidio(), $data, $map);
|
||||||
}
|
}
|
||||||
public function save(Define\Model $model): Model\Venta\Subsidio
|
public function save(Define\Model $model): Model\Venta\Subsidio
|
||||||
|
@ -19,11 +19,15 @@ class Proyecto
|
|||||||
{
|
{
|
||||||
return $this->proyectoRepository->fetchAllEscriturando();
|
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())
|
$proyecto->addFactory('estados', (new Implement\Repository\Factory())
|
||||||
->setCallable([$this->estadoProyecto, 'fetchByProyecto'])
|
->setCallable([$this->estadoProyecto, 'fetchByProyecto'])
|
||||||
|
@ -2,12 +2,18 @@
|
|||||||
namespace Incoviba\Service;
|
namespace Incoviba\Service;
|
||||||
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
|
|
||||||
class Search
|
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
|
public function query(string $query, string $tipo): array
|
||||||
{
|
{
|
||||||
@ -39,7 +45,12 @@ class Search
|
|||||||
}
|
}
|
||||||
protected function find(string $query, string $tipo): array
|
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();
|
$tiposUnidades = $this->getTiposUnidades();
|
||||||
$results = [];
|
$results = [];
|
||||||
foreach ($queries as $q) {
|
foreach ($queries as $q) {
|
||||||
@ -113,7 +124,8 @@ class Search
|
|||||||
protected function findProyecto(string $query): array
|
protected function findProyecto(string $query): array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->ventaService->getByProyecto($query);
|
$proyecto = $this->proyectoService->getByName($query);
|
||||||
|
return $this->ventaService->getByProyecto($proyecto->id);
|
||||||
} catch (EmptyResult) {
|
} catch (EmptyResult) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ class Venta
|
|||||||
return $venta;
|
return $venta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add(array $data): void
|
public function add(array $data): Model\Venta
|
||||||
{
|
{
|
||||||
$fecha = new DateTimeImmutable($data['fecha_venta']);
|
$fecha = new DateTimeImmutable($data['fecha_venta']);
|
||||||
$data['uf'] = $this->moneyService->getUF($fecha);
|
$data['uf'] = $this->moneyService->getUF($fecha);
|
||||||
@ -103,6 +103,8 @@ class Venta
|
|||||||
'fecha' => $venta->fecha->format('Y-m-d')
|
'fecha' => $venta->fecha->format('Y-m-d')
|
||||||
]);
|
]);
|
||||||
$this->estadoVentaRepository->save($estado);
|
$this->estadoVentaRepository->save($estado);
|
||||||
|
|
||||||
|
return $venta;
|
||||||
}
|
}
|
||||||
protected function addPropietario(array $data): Model\Venta\Propietario
|
protected function addPropietario(array $data): Model\Venta\Propietario
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user