From 8492d1df2b3e235b71f647d28018cd95348e7795 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Fri, 22 Dec 2023 12:52:04 -0300 Subject: [PATCH] Eliminar desistimiento y loading en editar desistimiento --- app/resources/routes/api/ventas.php | 5 +- .../views/ventas/desistida.blade.php | 66 ++++++++++++++----- app/src/Controller/API/Ventas.php | 12 ++++ app/src/Service/Venta.php | 16 ++++- app/src/Service/Venta/Pago.php | 15 ++++- 5 files changed, 96 insertions(+), 18 deletions(-) diff --git a/app/resources/routes/api/ventas.php b/app/resources/routes/api/ventas.php index 13b8000..a4acb3a 100644 --- a/app/resources/routes/api/ventas.php +++ b/app/resources/routes/api/ventas.php @@ -25,7 +25,10 @@ $app->group('/venta/{venta_id}', function($app) { $app->get('/unidades[/]', [Ventas::class, 'unidades']); $app->get('/comentarios[/]', [Ventas::class, 'comentarios']); $app->post('/escriturar[/]', [Ventas::class, 'escriturar']); - $app->post('/desistir[/]', [Ventas::class, 'desistir']); + $app->group('/desistir', function($app) { + $app->get('/eliminar[/]', [Ventas::class, 'insistir']); + $app->post('[/]', [Ventas::class, 'desistir']); + }); $app->post('[/]', [Ventas::class, 'edit']); $app->get('[/]', [Ventas::class, 'get']); }); diff --git a/app/resources/views/ventas/desistida.blade.php b/app/resources/views/ventas/desistida.blade.php index 4d394df..303c35a 100644 --- a/app/resources/views/ventas/desistida.blade.php +++ b/app/resources/views/ventas/desistida.blade.php @@ -9,35 +9,50 @@
-
- -
-
- - +
+
+ +
+
+ + +
-
-
- -
-
$
- +
+
+
+
+ +
+
$
+ +
+
+
+ +
+
+ +
@endsection @push('page_scripts') @endpush diff --git a/app/src/Controller/API/Ventas.php b/app/src/Controller/API/Ventas.php index 76e2ad5..684ec99 100644 --- a/app/src/Controller/API/Ventas.php +++ b/app/src/Controller/API/Ventas.php @@ -258,4 +258,16 @@ class Ventas } catch (EmptyResult) {} return $this->withJson($response, $output); } + public function insistir(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, int $venta_id): ResponseInterface + { + $output = [ + 'venta_id' => $venta_id, + 'eliminado' => false + ]; + try { + $venta = $ventaService->getById($venta_id); + $output['eliminado'] = $ventaService->insistir($venta); + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } } diff --git a/app/src/Service/Venta.php b/app/src/Service/Venta.php index 732c785..eecc7a2 100644 --- a/app/src/Service/Venta.php +++ b/app/src/Service/Venta.php @@ -384,7 +384,7 @@ class Venta { try { if ($this->validarData($data, ['fecha', 'devolucion'])) { - $pago = $this->pagoService->add(['fecha' => $data['fecha'], 'valor' => $data['devolucion']]); + $pago = $this->pagoService->add(['fecha' => $data['fecha'], 'valor' => str_replace(['.', ','], ['', '.'], $data['devolucion'])]); $this->ventaRepository->edit($venta, ['resciliacion' => $pago->id]); } $tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('desistida'); @@ -394,4 +394,18 @@ class Venta return false; } } + public function insistir(Model\Venta $venta): bool + { + try { + $pago = $venta->resciliacion(); + $this->pagoService->delete($pago); + $estado = $venta->currentEstado(); + error_log(var_export($estado,true)); + $this->estadoVentaRepository->remove($estado); + $this->ventaRepository->edit($venta, ['resciliacion' => null]); + return true; + } catch (Implement\Exception\EmptyResult) { + return false; + } + } } diff --git a/app/src/Service/Venta/Pago.php b/app/src/Service/Venta/Pago.php index 3d58e3a..9509a91 100644 --- a/app/src/Service/Venta/Pago.php +++ b/app/src/Service/Venta/Pago.php @@ -3,6 +3,7 @@ namespace Incoviba\Service\Venta; use DateTimeInterface; use DateTimeImmutable; +use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Service\Money; use PDOException; use Incoviba\Repository; @@ -66,8 +67,11 @@ class Pago return false; } } - public function getById(int $pago_id): Model\Venta\Pago + public function getById(?int $pago_id): ?Model\Venta\Pago { + if ($pago_id === null) { + return null; + } $pago = $this->pagoRepository->fetchById($pago_id); return $this->process($pago); } @@ -118,6 +122,15 @@ class Pago $pago->currentEstado = $estado; return $pago; } + public function delete(Model\Venta\Pago $pago): bool + { + try { + $this->pagoRepository->remove($pago); + return true; + } catch (EmptyResult|PDOException) { + return false; + } + } protected function process($pago): Model\Venta\Pago {