Mostrar alertas en inicio
This commit is contained in:
@ -21,6 +21,19 @@ class Proyectos
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function escriturando(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'total' => 0,
|
||||
'proyectos' => []
|
||||
];
|
||||
try {
|
||||
$proyectos = $proyectoRepository->fetchAllEscriturando();
|
||||
$output['proyectos'] = $proyectos;
|
||||
$output['total'] = count($proyectos);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
|
||||
|
138
app/src/Controller/API/Ventas.php
Normal file
138
app/src/Controller/API/Ventas.php
Normal file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Ventas
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = [
|
||||
'proyecto' => [
|
||||
'id' => $proyecto_id
|
||||
],
|
||||
'total' => 0
|
||||
];
|
||||
try {
|
||||
$ventas = $service->fetchActivaByProyecto($proyecto_id);
|
||||
$output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas);
|
||||
$output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion;
|
||||
$output['total'] = count($ventas);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$venta = $service->getById($venta_id);
|
||||
$output = compact('venta');
|
||||
} catch (EmptyResult $exception) {
|
||||
$output = [
|
||||
'error' => [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
|
||||
]
|
||||
];
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function porFirmar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'promesas' => 0
|
||||
];
|
||||
try {
|
||||
$ventas = $ventaService->getByProyecto($proyecto_id);
|
||||
$promesas = array_filter($ventas, function(Model\Venta $venta) {
|
||||
return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'vigente';
|
||||
});
|
||||
$output['promesas'] = count($promesas);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function escrituras(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'escrituras' => [
|
||||
'firmar' => 0,
|
||||
'pagar' => 0,
|
||||
'abonar' => 0
|
||||
]
|
||||
];
|
||||
try {
|
||||
$ventas = $ventaService->getEscriturasByProyecto($proyecto_id);
|
||||
$porFirmar = array_filter($ventas, function(Model\Venta $venta) {
|
||||
return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'escriturando';
|
||||
});
|
||||
$output['escrituras']['firmar'] = count($porFirmar);
|
||||
unset($porFirmar);
|
||||
$escrituras = array_filter($ventas, function(Model\Venta $venta) {
|
||||
return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'firmado por inmobiliaria';
|
||||
});
|
||||
unset($ventas);
|
||||
$porPagar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) {
|
||||
$pagos = $pagoService->getByVenta($venta->id);
|
||||
$porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) {
|
||||
return $pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado';
|
||||
});
|
||||
return count($porPagar) > 0;
|
||||
});
|
||||
$output['escrituras']['pagar'] = count($porPagar);
|
||||
unset($porPagar);
|
||||
$porAbonar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) {
|
||||
$pagos = $pagoService->getByVenta($venta->id);
|
||||
$porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) {
|
||||
return $pago->currentEstado->tipoEstadoPago->descripcion === 'depositado';
|
||||
});
|
||||
return count($porPagar) > 0;
|
||||
});
|
||||
$output['escrituras']['abonar'] = count($porAbonar);
|
||||
unset($porAbonar);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comentarios = $comentarioRepository->fetchByVenta($venta->id);
|
||||
$output['total'] = count($comentarios);
|
||||
$output['comentarios'] = $comentarios;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$output = [
|
||||
'status' => false,
|
||||
'errors' => []
|
||||
];
|
||||
try {
|
||||
$ventaService->add($data);
|
||||
$output['status'] = true;
|
||||
} catch (\Exception $exception) {
|
||||
$output['errors'] = $exception;
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
56
app/src/Controller/API/Ventas/Unidades.php
Normal file
56
app/src/Controller/API/Ventas/Unidades.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?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\withJson;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Unidades
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function disponibles(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, Repository\Proyecto\TipoUnidad $tipoUnidadRepository): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'unidades' => [
|
||||
'total' => [
|
||||
'departamentos' => 0,
|
||||
'estacionamientos' => 0,
|
||||
'bodegas' => 0,
|
||||
],
|
||||
'departamentos' => 0,
|
||||
'estacionamientos' => 0,
|
||||
'bodegas' => 0,
|
||||
]
|
||||
];
|
||||
try {
|
||||
$totalUnidades = $unidadRepository->fetchByProyecto($proyecto_id);
|
||||
$unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
|
||||
$tiposUnidades = $tipoUnidadRepository->fetchAll();
|
||||
foreach ($tiposUnidades as $tipoUnidad) {
|
||||
$tempUnidades = array_filter($totalUnidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) {
|
||||
return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id;
|
||||
});
|
||||
if (count($tempUnidades) > 0) {
|
||||
$output['unidades']['total']["{$tipoUnidad->descripcion}s"] = count($tempUnidades);
|
||||
}
|
||||
$tempUnidades = array_filter($unidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) {
|
||||
return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id;
|
||||
});
|
||||
if (count($tempUnidades) === 0) {
|
||||
continue;
|
||||
}
|
||||
$output['unidades']["{$tipoUnidad->descripcion}s"] = count($tempUnidades);
|
||||
}
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -28,39 +28,6 @@ class Ventas
|
||||
$venta = $service->getByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);
|
||||
return $view->render($response, 'ventas.show', compact('venta'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = [
|
||||
'proyecto' => [
|
||||
'id' => $proyecto_id
|
||||
],
|
||||
'total' => 0
|
||||
];
|
||||
try {
|
||||
$ventas = $service->fetchActivaByProyecto($proyecto_id);
|
||||
$output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas);
|
||||
$output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion;
|
||||
$output['total'] = count($ventas);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$venta = $service->getById($venta_id);
|
||||
$response->getBody()->write(json_encode(compact('venta')));
|
||||
} catch (EmptyResult $exception) {
|
||||
$response->getBody()->write(json_encode(['error' => [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
|
||||
]]));
|
||||
}
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
@ -90,18 +57,6 @@ class Ventas
|
||||
}
|
||||
return $view->render($response, 'ventas.propiedades.edit', compact('propiedad', 'proyecto', 'tiposUnidades', 'unidades', 'venta_id'));
|
||||
}
|
||||
public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comentarios = $comentarioRepository->fetchByVenta($venta->id);
|
||||
$output['total'] = count($comentarios);
|
||||
$output['comentarios'] = $comentarios;
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Region $regionRepository, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$regiones = $regionRepository->fetchAll();
|
||||
@ -111,22 +66,6 @@ class Ventas
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
|
||||
}
|
||||
public function doAdd(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$output = [
|
||||
'status' => false,
|
||||
'errors' => []
|
||||
];
|
||||
try {
|
||||
$ventaService->add($data);
|
||||
$output['status'] = true;
|
||||
} catch (\Exception $exception) {
|
||||
$output['errors'] = $exception;
|
||||
}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, View $view, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
|
Reference in New Issue
Block a user