Implemented repository mapper, and venta show
This commit is contained in:
39
app/src/Controller/Direcciones.php
Normal file
39
app/src/Controller/Direcciones.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
@ -14,8 +15,13 @@ class Proyectos
|
||||
}
|
||||
public function list(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
$response->getBody()->write(json_encode(['proyectos' => $proyectos, 'total' => count($proyectos)]));
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
$output['proyectos'] = $proyectos;
|
||||
$output['total'] = count($proyectos);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use MongoDB\Driver\Server;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Ventas
|
||||
{
|
||||
@ -14,13 +17,89 @@ class Ventas
|
||||
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
|
||||
return $view->render($response, 'ventas.list', compact('proyectos'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service): ResponseInterface
|
||||
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 proyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$ventas = $service->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['ventas' => $ventas, 'total' => count($ventas)]));
|
||||
$output = [
|
||||
'proyecto' => [
|
||||
'id' => $proyecto_id
|
||||
],
|
||||
'total' => 0
|
||||
];
|
||||
try {
|
||||
$ventas = $service->fetchByProyecto($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);
|
||||
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 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');
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?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;
|
||||
@ -12,19 +13,24 @@ class Cierres
|
||||
{
|
||||
return $view->render($response, 'ventas.cierres.list');
|
||||
}
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Ventas\Cierre $service, int $cierre_id): ResponseInterface
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta\Cierre $service, int $cierre_id): ResponseInterface
|
||||
{
|
||||
$cierre = $service->getById($cierre_id);
|
||||
return $view->render($response, 'ventas.cierres.show', compact('cierre'));
|
||||
}
|
||||
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Cierre $service): ResponseInterface
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Cierre $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$cierres = $service->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['cierres' => $cierres, 'total' => count($cierres)]));
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$cierres = $service->getByProyecto($proyecto_id);
|
||||
$output['cierres'] = $cierres;
|
||||
$output['total'] = count($cierres);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
22
app/src/Controller/Ventas/Comentarios.php
Normal file
22
app/src/Controller/Ventas/Comentarios.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Comentarios
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Comentario $comentarioRepository): ResponseInterface
|
||||
{
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comentarios = $comentarioRepository->fetchAll();
|
||||
$output['comentarios'] = $comentarios;
|
||||
$output['total'] = count($comentarios);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use IntlDateFormatter;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
@ -44,16 +45,19 @@ class Cuotas
|
||||
}
|
||||
return $view->render($response, 'ventas.cuotas.pendientes', compact('cuotas_pendientes'));
|
||||
}
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Ventas\Pago $pagoService): ResponseInterface
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$cuota_id = $json->cuota_id;
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output = [
|
||||
'cuota_id' => $cuota_id,
|
||||
'depositada' => $pagoService->depositar($cuota->pago)
|
||||
'depositada' => false
|
||||
];
|
||||
try{
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['depositada'] = $pagoService->depositar($cuota->pago);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
26
app/src/Controller/Ventas/Pagos.php
Normal file
26
app/src/Controller/Ventas/Pagos.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class Pagos
|
||||
{
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$date = new DateTimeImmutable($json->fecha);
|
||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$date = new DateTimeImmutable($json->fecha);
|
||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?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;
|
||||
@ -14,18 +15,23 @@ 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\Ventas\Precio $precioService): ResponseInterface
|
||||
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;
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['precios' => $precios, 'total' => count($precios)]));
|
||||
$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\Ventas\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
{
|
||||
$precio = $precioService->getByUnidad($unidad_id);
|
||||
$precio = $precioService->getVigenteByUnidad($unidad_id);
|
||||
$response->getBody()->write(json_encode(['precio' => $precio]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
15
app/src/Controller/Ventas/Propietarios.php
Normal file
15
app/src/Controller/Ventas/Propietarios.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Propietarios
|
||||
{
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Venta\Propietario $propietarioRepository, int $propietario_rut): ResponseInterface
|
||||
{
|
||||
$propietario = $propietarioRepository->fetchById($propietario_rut);
|
||||
return $view->render($response, 'ventas.propietarios.show', compact('propietario'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user