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