From 169ca6172951234274ccdeef1ab343e775565f85 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Fri, 11 Apr 2025 13:32:52 -0400 Subject: [PATCH] Rutas y controladores para editar bono --- app/resources/routes/04_ventas.php | 2 ++ app/resources/routes/api/ventas.php | 1 + app/resources/routes/ventas/pies/bonos.php | 2 ++ app/src/Controller/API/Ventas/Bonos.php | 24 +++++++++++++++++++++- app/src/Controller/Ventas/Bonos.php | 11 +++++++++- 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/app/resources/routes/04_ventas.php b/app/resources/routes/04_ventas.php index 2ce4212..3834184 100644 --- a/app/resources/routes/04_ventas.php +++ b/app/resources/routes/04_ventas.php @@ -29,7 +29,9 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) { $app->get('[/]', [Ventas::class, 'pie']); }); $app->group('/bono_pie', function($app) { + $app->get('/edit[/]', [Ventas\Bonos::class, 'edit']); $app->get('/add[/]', [Ventas\Bonos::class, 'add']); + $app->get('[/]', [Ventas\Bonos::class, 'edit']); }); $app->group('/escritura', function($app) { $app->group('/cuotas', function($app) { diff --git a/app/resources/routes/api/ventas.php b/app/resources/routes/api/ventas.php index c79874b..02833f8 100644 --- a/app/resources/routes/api/ventas.php +++ b/app/resources/routes/api/ventas.php @@ -32,6 +32,7 @@ $app->group('/venta/{venta_id}', function($app) { $app->get('[/]', [Ventas::class, 'comentarios']); }); $app->group('/bono_pie', function($app) { + $app->post('/edit[/]', [Ventas\Bonos::class, 'edit']); $app->post('/add[/]', [Ventas\Bonos::class, 'add']); }); $app->group('/escritura', function($app) { diff --git a/app/resources/routes/ventas/pies/bonos.php b/app/resources/routes/ventas/pies/bonos.php index 93b0970..8328bf3 100644 --- a/app/resources/routes/ventas/pies/bonos.php +++ b/app/resources/routes/ventas/pies/bonos.php @@ -2,5 +2,7 @@ use Incoviba\Controller\Ventas\Bonos; $app->group('/bono_pie', function($app) { + $app->get('/edit[/]', [Bonos::class, 'edit']); $app->get('/add[/]', [Bonos::class, 'add']); + $app->get('[/]', [Bonos::class, 'edit']); }); diff --git a/app/src/Controller/API/Ventas/Bonos.php b/app/src/Controller/API/Ventas/Bonos.php index dce6194..8caf6d0 100644 --- a/app/src/Controller/API/Ventas/Bonos.php +++ b/app/src/Controller/API/Ventas/Bonos.php @@ -7,8 +7,9 @@ use Psr\Http\Message\ServerRequestInterface; use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Common\Ideal\Controller; use Incoviba\Controller\API\withJson; -use Incoviba\Service; +use Incoviba\Exception\ServiceAction\Update; use Incoviba\Repository; +use Incoviba\Service; class Bonos extends Controller { @@ -39,4 +40,25 @@ class Bonos extends Controller } catch (EmptyResult) {} return $this->withJson($response, $output); } + public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, + Service\Venta\BonoPie $bonoPieService, int $venta_id): ResponseInterface + { + $input = $request->getParsedBody(); + $output = [ + 'venta_id' => $venta_id, + 'input' => $input, + 'bono' => null, + 'success' => false, + ]; + try { + try { + $venta = $ventaService->getById($venta_id); + } catch (EmptyResult $exception) { + throw new Update(__CLASS__, $exception); + } + $output['bono'] = $bonoPieService->edit($venta->formaPago()->bonoPie, $input); + $output['success'] = true; + } catch (Update) {} + return $this->withJson($response, $output); + } } diff --git a/app/src/Controller/Ventas/Bonos.php b/app/src/Controller/Ventas/Bonos.php index 510f31a..d710ba1 100644 --- a/app/src/Controller/Ventas/Bonos.php +++ b/app/src/Controller/Ventas/Bonos.php @@ -4,14 +4,23 @@ namespace Incoviba\Controller\Ventas; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Incoviba\Common\Alias\View; -use Incoviba\Repository; use Incoviba\Service; class Bonos { + public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $ventaService, int $venta_id): ResponseInterface + { + $venta = $ventaService->getById($venta_id); + return $view->render($response, 'ventas.pies.bonos.show', compact('venta')); + } public function add(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $ventaService, int $venta_id): ResponseInterface { $venta = $ventaService->getById($venta_id); return $view->render($response, 'ventas.pies.bonos.add', compact('venta')); } + public function edit(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $ventaService, int $venta_id): ResponseInterface + { + $venta = $ventaService->getById($venta_id); + return $view->render($response, 'ventas.pies.bonos.edit', compact('venta')); + } }