Implemented repository mapper, and venta show

This commit is contained in:
Juan Pablo Vial
2023-08-08 23:53:49 -04:00
parent ef30ae67d2
commit 59825259b6
111 changed files with 2766 additions and 612 deletions

View File

@ -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');
}
}

View 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');
}
}

View File

@ -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');
}

View 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');
}
}

View File

@ -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');
}

View 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'));
}
}