89 lines
4.4 KiB
PHP
89 lines
4.4 KiB
PHP
<?php
|
|
namespace Incoviba\Controller;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Incoviba\Common\Alias\View;
|
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
|
use Incoviba\Model;
|
|
use Incoviba\Repository;
|
|
use Incoviba\Service;
|
|
|
|
class Ventas
|
|
{
|
|
use withRedis;
|
|
|
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
|
Service\Redis $redisService, Service\Proyecto $proyectoService,
|
|
Repository\Proyecto $proyectoRepository): ResponseInterface
|
|
{
|
|
$redisKey = "proyectos:vendibles";
|
|
try {
|
|
$proyectos = $this->fetchRedis($redisService, $redisKey);
|
|
} catch (EmptyRedis) {
|
|
$proyectos = array_map(function(Model\Proyecto $proyecto) {
|
|
return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];
|
|
}, $proyectoService->getVendibles());
|
|
$this->saveRedis($redisService, $redisKey, $proyectos);
|
|
}
|
|
return $view->render($response, 'ventas.list', compact('proyectos'));
|
|
}
|
|
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
|
Service\Venta $service, int $venta_id): ResponseInterface
|
|
{
|
|
$venta = $service->getById($venta_id);
|
|
return $view->render($response, 'ventas.show', compact('venta'));
|
|
}
|
|
public function showUnidad(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
|
Service\Venta $service, string $proyecto_nombre, int $unidad_descripcion): ResponseInterface
|
|
{
|
|
$proyecto_nombre = urldecode($proyecto_nombre);
|
|
$venta = $service->getByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);
|
|
return $view->render($response, 'ventas.show', compact('venta'));
|
|
}
|
|
public function edit(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface
|
|
{
|
|
$venta = $service->getById($venta_id);
|
|
return $view->render($response, 'ventas.edit', compact('venta'));
|
|
}
|
|
public function propietario(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, Repository\Region $regionRepository, int $venta_id): ResponseInterface
|
|
{
|
|
$venta = $service->getById($venta_id);
|
|
$propietario = $venta->propietario();
|
|
$regiones = $regionRepository->fetchAll();
|
|
usort($regiones, function(Model\Region $a, Model\Region $b) {
|
|
return $a->numeracion - $b->numeracion;
|
|
});
|
|
return $view->render($response, 'ventas.propietarios.edit', compact('propietario', 'venta_id', 'regiones'));
|
|
}
|
|
public function propiedad(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, Service\Venta\Unidad $unidadService, int $venta_id): ResponseInterface
|
|
{
|
|
$venta = $service->getById($venta_id);
|
|
$propiedad = $venta->propiedad();
|
|
$proyecto = $venta->proyecto();
|
|
$unidades = $unidadService->getDisponiblesByProyecto($proyecto->id);
|
|
$tiposUnidades = [];
|
|
foreach ($unidades as $unidad) {
|
|
if (!in_array($unidad->proyectoTipoUnidad->tipoUnidad, $tiposUnidades)) {
|
|
$tiposUnidades []= $unidad->proyectoTipoUnidad->tipoUnidad;
|
|
}
|
|
}
|
|
return $view->render($response, 'ventas.propiedades.edit', compact('propiedad', 'proyecto', 'tiposUnidades', 'unidades', 'venta_id'));
|
|
}
|
|
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Region $regionRepository, Repository\Proyecto $proyectoRepository): ResponseInterface
|
|
{
|
|
$regiones = $regionRepository->fetchAll();
|
|
usort($regiones, function(Model\Region $a, Model\Region $b) {
|
|
return $a->numeracion - $b->numeracion;
|
|
});
|
|
$proyectos = $proyectoRepository->fetchAllActive();
|
|
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
|
|
}
|
|
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, View $view, int $venta_id): ResponseInterface
|
|
{
|
|
$venta = $ventaService->getById($venta_id);
|
|
return $view->render($response, 'ventas.pies.cuotas', compact('venta'));
|
|
}
|
|
}
|