Files
oficial/app/src/Controller/Ventas.php

151 lines
7.4 KiB
PHP
Raw Normal View History

2023-07-28 16:22:20 -04:00
<?php
namespace Incoviba\Controller;
use Incoviba\Common\Alias\View;
2023-11-23 00:53:49 -03:00
use Incoviba\Common\Implement\Exception\EmptyRedis;
2024-03-26 09:38:20 -03:00
use Incoviba\Common\Implement\Exception\EmptyResult;
2023-07-28 16:22:20 -04:00
use Incoviba\Model;
use Incoviba\Repository;
2023-11-23 00:53:49 -03:00
use Incoviba\Service;
2024-03-26 09:38:20 -03:00
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
2023-07-28 16:22:20 -04:00
class Ventas
{
2023-11-23 00:53:49 -03:00
use withRedis;
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Redis $redisService, Service\Proyecto $proyectoService,
Repository\Proyecto $proyectoRepository): ResponseInterface
2023-07-28 16:22:20 -04:00
{
2023-11-23 00:53:49 -03:00
$redisKey = "proyectos:vendibles";
try {
2023-11-23 23:35:19 -03:00
$proyectos = $this->fetchRedis($redisService, $redisKey);
2023-11-23 00:53:49 -03:00
} catch (EmptyRedis) {
$proyectos = array_map(function(Model\Proyecto $proyecto) {
return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];
}, $proyectoService->getVendibles());
$this->saveRedis($redisService, $redisKey, $proyectos);
}
2023-07-28 16:22:20 -04:00
return $view->render($response, 'ventas.list', compact('proyectos'));
}
2023-11-23 00:53:49 -03:00
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta $service, int $venta_id): ResponseInterface
{
2024-03-13 14:38:44 -03:00
try {
$venta = $service->getById($venta_id);
return $view->render($response, 'ventas.show', compact('venta'));
} catch (EmptyResult) {
$response = $response->withStatus(404);
return $view->render($response, 'not_found');
}
}
2023-11-23 00:53:49 -03:00
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'));
}
2023-12-20 08:44:49 -03:00
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'));
}
2023-12-20 08:44:49 -03:00
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;
});
2023-12-20 08:44:49 -03:00
return $view->render($response, 'ventas.propietarios.edit', compact('propietario',
'venta_id', 'regiones'));
}
2023-12-20 08:44:49 -03:00
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;
}
}
2023-12-20 08:44:49 -03:00
return $view->render($response, 'ventas.propiedades.edit', compact('propiedad',
'proyecto', 'tiposUnidades', 'unidades', 'venta'));
}
2023-12-20 08:44:49 -03:00
public function pie(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta $service, int $venta_id): ResponseInterface
2023-11-29 22:21:46 -03:00
{
$venta = $service->getById($venta_id);
return $view->render($response, 'ventas.pies.edit', compact('venta'));
}
2023-12-20 08:44:49 -03:00
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view,
Repository\Region $regionRepository, Repository\Proyecto $proyectoRepository): ResponseInterface
2023-09-07 23:03:21 -03:00
{
$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'));
}
2023-12-20 08:44:49 -03:00
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
2024-10-23 08:39:11 -03:00
Service\Contabilidad\Banco $bancoService,
2024-11-06 21:28:36 -03:00
Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
2023-12-20 08:44:49 -03:00
View $view, int $venta_id): ResponseInterface
2023-09-13 18:51:46 -03:00
{
$venta = $ventaService->getById($venta_id);
$asociadas = [];
if (isset($venta->formaPago()->pie->asociado)) {
$asociadas []= $ventaService->getByPie($venta->formaPago()->pie->asociado->id);
foreach ($venta->formaPago()->pie->asociado->asociados() as $asociado) {
if ($venta->formaPago()->pie->id === $asociado->id) {
continue;
}
$asociadas []= $ventaService->getByPie($asociado->id);
}
}
2024-03-26 16:41:33 -03:00
if (count($venta->formaPago()->pie->asociados()) > 0) {
foreach ($venta->formaPago()->pie->asociados() as $asociado) {
2024-05-09 21:04:51 -04:00
if ($asociado->id === $venta->formaPago()->pie->id) {
continue;
}
2024-03-26 16:41:33 -03:00
$asociadas []= $ventaService->getByPie($asociado->id);
}
}
2024-11-06 21:28:36 -03:00
$bancos = $bancoService->getAll('nombre');
$estados = $tipoEstadoPagoRepository->fetchAll('descripcion');
return $view->render($response, 'ventas.pies.cuotas', compact('venta', 'asociadas', 'bancos', 'estados'));
2023-09-13 18:51:46 -03:00
}
2024-03-26 09:38:20 -03:00
public function escriturar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
Repository\Contabilidad\Banco $bancoRepository, View $view, int $venta_id): ResponseInterface
2023-12-20 08:44:49 -03:00
{
$venta = $ventaService->getById($venta_id);
$bancos = $bancoRepository->fetchAll();
2024-03-26 09:38:20 -03:00
usort($bancos, function(Model\Contabilidad\Banco $a, Model\Contabilidad\Banco $b) {
2023-12-20 08:44:49 -03:00
return strcmp($a->nombre, $b->nombre);
});
return $view->render($response, 'ventas.escriturar', compact('venta', 'bancos'));
}
2023-12-21 18:45:47 -03:00
public function desistir(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
View $view, int $venta_id): ResponseInterface
{
$venta = $ventaService->getById($venta_id);
return $view->render($response, 'ventas.desistir', compact('venta'));
}
2023-12-21 21:06:38 -03:00
public function desistida(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
View $view, int $venta_id): ResponseInterface
{
$venta = $ventaService->getById($venta_id);
return $view->render($response, 'ventas.desistida', compact('venta'));
}
2023-07-28 16:22:20 -04:00
}