Show Proyecto
This commit is contained in:
@ -3,13 +3,15 @@ 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\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
use withJson;
|
||||
use withJson, withRedis;
|
||||
|
||||
public function list(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
@ -34,26 +36,88 @@ class Proyectos
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Venta\Unidad $unidadRepository, Service\Redis $redisService,
|
||||
int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
|
||||
$redisKey = "unidades-proyecto-{$proyecto_id}";
|
||||
try {
|
||||
$unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
$tipos = [];
|
||||
foreach ($unidades as $unidad) {
|
||||
if (!isset($tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion])) {
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] = [];
|
||||
$output = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$unidades = $unidadRepository->fetchByProyecto($proyecto_id);
|
||||
$tipos = [];
|
||||
foreach ($unidades as $unidad) {
|
||||
if (!isset($tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion])) {
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] = [];
|
||||
}
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] []= $unidad;
|
||||
}
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] []= $unidad;
|
||||
}
|
||||
foreach ($tipos as &$subtipo) {
|
||||
usort($subtipo, function(Model\Venta\Unidad $a, Model\Venta\Unidad $b) {
|
||||
return strcmp(str_pad($a->descripcion, 4, '0', STR_PAD_LEFT), str_pad($b->descripcion, 4, '0', STR_PAD_LEFT));
|
||||
});
|
||||
}
|
||||
$output['unidades'] = $tipos;
|
||||
$output['total'] = count($unidades);
|
||||
foreach ($tipos as &$subtipo) {
|
||||
usort($subtipo, function(Model\Venta\Unidad $a, Model\Venta\Unidad $b) {
|
||||
return strcmp(str_pad($a->descripcion, 4, '0', STR_PAD_LEFT), str_pad($b->descripcion, 4, '0', STR_PAD_LEFT));
|
||||
});
|
||||
}
|
||||
$output['unidades'] = $tipos;
|
||||
$output['total'] = count($unidades);
|
||||
$this->saveRedis($redisService, $redisKey, $output);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function disponibles(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'unidades' => []
|
||||
];
|
||||
try {
|
||||
$output['unidades'] = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
} 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
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'superficies' => [
|
||||
'vendible' => 0,
|
||||
'vendido' => 0,
|
||||
'por_vender' => 0
|
||||
],
|
||||
'formatted' => [
|
||||
'vendible' => '0m²',
|
||||
'vendido' => '0m²',
|
||||
'por_vender' => '0m²'
|
||||
]
|
||||
];
|
||||
$redisKey = "superficices-proyecto-{$proyecto_id}";
|
||||
try {
|
||||
$output = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$ventas = $ventaRepository->fetchActivaByProyecto($proyecto_id);
|
||||
$unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
|
||||
$output['superficies']['vendido'] = array_reduce($ventas, function($sum, Model\Venta $venta) {
|
||||
return $sum + array_reduce($venta->propiedad()->unidades, function($sum, Model\Venta\Unidad $unidad) {
|
||||
return $sum + $unidad->proyectoTipoUnidad->vendible();
|
||||
});
|
||||
}, 0);
|
||||
$output['formatted']['vendido'] = "{$formatService->number($output['superficies']['vendido'], 2)}m²";
|
||||
$output['superficies']['por_vender'] = array_reduce($unidades, function($sum, Model\Venta\Unidad $unidad) {
|
||||
return $sum + $unidad->proyectoTipoUnidad->vendible();
|
||||
});
|
||||
$output['formatted']['por_vender'] = "{$formatService->number($output['superficies']['por_vender'], 2)}m²";
|
||||
$output['superficies']['vendible'] = $output['superficies']['vendido'] + $output['superficies']['por_vender'];
|
||||
$output['formatted']['vendible'] = "{$formatService->number($output['superficies']['vendible'], 2)}m²";
|
||||
$this->saveRedis($redisService, $redisKey, $output, 60 * 60);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class Ventas
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "promesas_por_firmar-{$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 +80,7 @@ class Ventas
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "escrituras-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
$redisKey = "escrituras-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
|
36
app/src/Controller/API/Ventas/Precios.php
Normal file
36
app/src/Controller/API/Ventas/Precios.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Precios
|
||||
{
|
||||
use API\withJson, API\emptyBody;
|
||||
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$output['precios'] = $precios;
|
||||
$output['total'] = count($precios);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$precio = $precioService->getVigenteByUnidad($unidad_id);
|
||||
return $this->withJson($response, compact('precio'));
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
}
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ class Unidades
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "unidades_disponibles-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
$redisKey = "unidades_disponibles-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
|
@ -4,8 +4,9 @@ namespace Incoviba\Controller;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
@ -29,4 +30,9 @@ class 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
|
||||
{
|
||||
$proyecto = $proyectoService->getById($proyecto_id);
|
||||
return $view->render($response, 'proyectos.show', compact('proyecto'));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
@ -15,24 +14,4 @@ class Precios
|
||||
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
|
||||
return $view->render($response, 'ventas.precios.list', compact('proyectos'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$output['precios'] = $precios;
|
||||
$output['total'] = count($precios);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
{
|
||||
$precio = $precioService->getVigenteByUnidad($unidad_id);
|
||||
$response->getBody()->write(json_encode(['precio' => $precio]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Alias\Model;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Proyecto extends Ideal\Model
|
||||
@ -15,6 +16,9 @@ class Proyecto extends Ideal\Model
|
||||
public int $subterraneos;
|
||||
protected Proyecto\Etapa $etapa;
|
||||
|
||||
protected array $estados;
|
||||
protected Proyecto\EstadoProyecto $currentEstado;
|
||||
|
||||
public function inmobiliaria(): Inmobiliaria
|
||||
{
|
||||
if (!isset($this->inmobiliaria)) {
|
||||
@ -29,6 +33,20 @@ class Proyecto extends Ideal\Model
|
||||
}
|
||||
return $this->direccion;
|
||||
}
|
||||
public function estados(): array
|
||||
{
|
||||
if (!isset($this->estados)) {
|
||||
$this->estados = $this->runFactory('estados');
|
||||
}
|
||||
return $this->estados;
|
||||
}
|
||||
public function currentEstado(): Proyecto\EstadoProyecto
|
||||
{
|
||||
if (!isset($this->currentEstado)) {
|
||||
$this->currentEstado = $this->runFactory('currentEstado');
|
||||
}
|
||||
return $this->currentEstado;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
|
@ -5,4 +5,9 @@ class Superficie
|
||||
{
|
||||
public float $sobre_nivel;
|
||||
public float $bajo_nivel;
|
||||
|
||||
public function total(): float
|
||||
{
|
||||
return $this->bajo_nivel + $this->sobre_nivel;
|
||||
}
|
||||
}
|
||||
|
@ -9,15 +9,15 @@ class Propiedad extends Ideal\Model
|
||||
|
||||
public function departamentos(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';});
|
||||
return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';}));
|
||||
}
|
||||
public function estacionamientos(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'estacionamiento';});
|
||||
return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'estacionamiento';}));
|
||||
}
|
||||
public function bodegas(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';});
|
||||
return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';}));
|
||||
}
|
||||
|
||||
protected float $vendible;
|
||||
|
@ -92,6 +92,10 @@ WHERE et.`orden` BETWEEN {$etapaRecepcion->orden} AND ({$etapaTerminado->orden}
|
||||
ORDER BY a.`descripcion`";
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
public function fetchSuperficieVendido(int $proyecto_id): float
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function joinEstado(): string
|
||||
{
|
||||
|
@ -15,8 +15,8 @@ class Redis
|
||||
}
|
||||
return $this->client->get($name);
|
||||
}
|
||||
public function set(string $name, mixed $value): void
|
||||
public function set(string $name, mixed $value, int $expirationTTL = 60 * 60 * 24): void
|
||||
{
|
||||
$this->client->set($name, $value, 'EX', 60 * 60 * 24);
|
||||
$this->client->set($name, $value, 'EX', $expirationTTL);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user