From 3ce41914e5216b178025169af43d163c27e48008 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Fri, 18 Jul 2025 16:15:30 -0400 Subject: [PATCH] FIX: Venta desistida pero sin resciliacion --- .../views/ventas/desistida.blade.php | 7 ++++--- app/src/Controller/Ventas.php | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/resources/views/ventas/desistida.blade.php b/app/resources/views/ventas/desistida.blade.php index 092412f..252d33f 100644 --- a/app/resources/views/ventas/desistida.blade.php +++ b/app/resources/views/ventas/desistida.blade.php @@ -54,15 +54,16 @@ } $(document).ready(() => { const url = '{{$urls->api}}/ventas/pago/{{$venta->resciliacion()->id}}' - let old = new Date({{$venta->resciliacion()?->fecha->format('Y') ?? date('Y')}}, - {{$venta->resciliacion()?->fecha->format('n') ?? date('n')}}-1, {{$venta->resciliacion()?->fecha->format('j') ?? date('j')}}) + let old = new Date(Date.parse('{{$venta->resciliacion()?->fecha->format('Y-m-d') ?? $venta->currentEstado()->fecha->format('Y-m-d') ?? $venta->fecha->format('Y-m-d')}}') + 24 * 60 * 60 * 1000) calendar_date_options['initialDate'] = old calendar_date_options['onChange'] = function(date, text, mode) { if (date.getTime() === old.getTime()) { return } const body = new FormData() - body.set('fecha', date.toISOString()) + const fecha = date + fecha.setDate(date.getDate() - 1) + body.set('fecha', fecha.toISOString()) $('#loading-spinner-fecha').show() APIClient.fetch(url, {method: 'post', body}).then(response => { $('#loading-spinner-fecha').hide() diff --git a/app/src/Controller/Ventas.php b/app/src/Controller/Ventas.php index 93efc85..225afa1 100644 --- a/app/src/Controller/Ventas.php +++ b/app/src/Controller/Ventas.php @@ -4,6 +4,9 @@ namespace Incoviba\Controller; use Incoviba\Common\Alias\View; use Incoviba\Common\Implement\Exception\EmptyRedis; use Incoviba\Common\Implement\Exception\EmptyResult; +use Incoviba\Exception\ServiceAction\Create; +use Incoviba\Exception\ServiceAction\Read; +use Incoviba\Exception\ServiceAction\Update; use Incoviba\Model; use Incoviba\Repository; use Incoviba\Service; @@ -142,9 +145,24 @@ class Ventas return $view->render($response, 'ventas.desistir', compact('venta')); } public function desistida(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, + Service\Venta\Pago $pagoService, View $view, int $venta_id): ResponseInterface { - $venta = $ventaService->getById($venta_id); + try { + $venta = $ventaService->getById($venta_id); + } catch (Read) { + return $view->render($response->withStatus(404), 'not_found'); + } + if ($venta->resciliacion() === null) { + $pagoData = [ + 'fecha' => $venta->currentEstado()->fecha->format('Y-m-d'), + 'valor' => 0 + ]; + try { + $pago = $pagoService->add($pagoData); + $ventaService->edit($venta, ['resciliacion' => $pago->id]); + } catch (Create | Update) {} + } return $view->render($response, 'ventas.desistida', compact('venta')); } }