From 37c28c30800aaa54f2d78f55d01667514c692a3e Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Wed, 6 Nov 2024 21:28:36 -0300 Subject: [PATCH] Editar estado cuota --- app/resources/routes/api/ventas/pagos.php | 1 + .../views/ventas/pies/cuotas.blade.php | 28 ++++++ .../ventas/pies/cuotas/estados/edit.blade.php | 93 +++++++++++++++++++ app/src/Controller/API/Ventas/Pagos.php | 25 +++++ app/src/Controller/Ventas.php | 9 +- app/src/Controller/Ventas/Pies.php | 9 +- 6 files changed, 155 insertions(+), 10 deletions(-) create mode 100644 app/resources/views/ventas/pies/cuotas/estados/edit.blade.php diff --git a/app/resources/routes/api/ventas/pagos.php b/app/resources/routes/api/ventas/pagos.php index 784f146..71726bf 100644 --- a/app/resources/routes/api/ventas/pagos.php +++ b/app/resources/routes/api/ventas/pagos.php @@ -11,5 +11,6 @@ $app->group('/pago/{pago_id:[0-9]+}', function($app) { $app->post('/abonar[/]', [Pagos::class, 'abonar']); $app->post('/devolver[/]', [Pagos::class, 'devolver']); $app->get('/anular[/]', [Pagos::class, 'anular']); + $app->post('/estado[/]', [Pagos::class, 'estado']); $app->post('[/]', [Pagos::class, 'edit']); }); diff --git a/app/resources/views/ventas/pies/cuotas.blade.php b/app/resources/views/ventas/pies/cuotas.blade.php index 36f6b25..49f734a 100644 --- a/app/resources/views/ventas/pies/cuotas.blade.php +++ b/app/resources/views/ventas/pies/cuotas.blade.php @@ -7,6 +7,7 @@ @push('page_scripts') @endpush @@ -89,6 +90,11 @@ ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado' ? ' class="yellow"' : ($cuota->pago->currentEstado->tipoEstadoPago->activo !== 1 ? ' class="red"' : ''))) !!}> {{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}} + @if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['abonado', 'anulado', 'reemplazado'])) @@ -185,6 +191,7 @@ @include('ventas.pies.cuotas.edit') + @include('ventas.pies.cuotas.estados.edit') @endsection @include('layout.head.styles.datatables') @@ -329,6 +336,27 @@ editModal.open({id, number, fecha, banco_id, identificador, valor}) }) + const editCuotaModal = new EditEstadoModal({id: '#edit_estado_cuota_modal', approve: ({id, data}) => { + const url = '{{$urls->api}}/ventas/pago/' + id + '/estado' + return fetchAPI(url, {method: 'post', body: data}).then(response => { + if (!response) { + return + } + return response.json().then(json => { + if (!json.editado) { + return + } + window.location.reload() + }) + }) + }}) + $('.edit_estado_cuota').on('click', clickEvent => { + const id = $(clickEvent.currentTarget).data('cuota') + const estado_id = $(clickEvent.currentTarget).data('estado') + const fecha = $(clickEvent.currentTarget).data('fecha') + + editCuotaModal.open({id, estado_id, fecha}) + }) $('.fecha_estado').calendar({ type: 'date', formatter: { diff --git a/app/resources/views/ventas/pies/cuotas/estados/edit.blade.php b/app/resources/views/ventas/pies/cuotas/estados/edit.blade.php new file mode 100644 index 0000000..1290fcb --- /dev/null +++ b/app/resources/views/ventas/pies/cuotas/estados/edit.blade.php @@ -0,0 +1,93 @@ + + +@push('page_scripts') + +@endpush diff --git a/app/src/Controller/API/Ventas/Pagos.php b/app/src/Controller/API/Ventas/Pagos.php index b7f4425..ea8d5f7 100644 --- a/app/src/Controller/API/Ventas/Pagos.php +++ b/app/src/Controller/API/Ventas/Pagos.php @@ -57,6 +57,31 @@ class Pagos } catch (EmptyResult) {} return $this->withJson($response, $output); } + public function estado(ServerRequestInterface $request, ResponseInterface $response, + Service\Venta\Pago $pagoService, + Repository\Venta\EstadoPago $estadoPagoRepository, + int $pago_id): ResponseInterface + { + $body = $request->getParsedBody(); + $output = [ + 'pago_id' => $pago_id, + 'input' => $body, + 'pago' => null, + 'editado' => false + ]; + try { + $pago = $pagoService->getById($pago_id); + $output['pago'] = $pago; + $estado = $estadoPagoRepository->create([ + 'pago' => $pago->id, + 'estado' => $body['estado'], + 'fecha' => $body['fecha'] + ]); + $estadoPagoRepository->save($estado); + $output['editado'] = true; + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } /** * @param ServerRequestInterface $request diff --git a/app/src/Controller/Ventas.php b/app/src/Controller/Ventas.php index c9bd461..93efc85 100644 --- a/app/src/Controller/Ventas.php +++ b/app/src/Controller/Ventas.php @@ -99,6 +99,7 @@ class Ventas } public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Service\Contabilidad\Banco $bancoService, + Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository, View $view, int $venta_id): ResponseInterface { $venta = $ventaService->getById($venta_id); @@ -120,11 +121,9 @@ class Ventas $asociadas []= $ventaService->getByPie($asociado->id); } } - $bancos = $bancoService->getAll(); - usort($bancos, function($a, $b) { - return strcmp($a->nombre, $b->nombre); - }); - return $view->render($response, 'ventas.pies.cuotas', compact('venta', 'asociadas', 'bancos')); + $bancos = $bancoService->getAll('nombre'); + $estados = $tipoEstadoPagoRepository->fetchAll('descripcion'); + return $view->render($response, 'ventas.pies.cuotas', compact('venta', 'asociadas', 'bancos', 'estados')); } public function escriturar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Repository\Contabilidad\Banco $bancoRepository, View $view, int $venta_id): ResponseInterface diff --git a/app/src/Controller/Ventas/Pies.php b/app/src/Controller/Ventas/Pies.php index dacb0f5..3fb9fcc 100644 --- a/app/src/Controller/Ventas/Pies.php +++ b/app/src/Controller/Ventas/Pies.php @@ -12,14 +12,13 @@ class Pies { public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService, Repository\Venta $ventaRepository, Repository\Contabilidad\Banco $bancoRepository, + Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository, View $view, int $pie_id): ResponseInterface { $pie = $pieService->getById($pie_id); $venta = $ventaRepository->fetchByPie($pie_id); - $bancos = $bancoRepository->fetchAll(); - usort($bancos, function(Model\Contabilidad\Banco $a, Model\Contabilidad\Banco $b) { - return strcmp($a->nombre, $b->nombre); - }); - return $view->render($response, 'ventas.pies.cuotas', compact('pie', 'venta', 'bancos', 'ventaRepository')); + $bancos = $bancoRepository->fetchAll('nombre'); + $estados = $tipoEstadoPagoRepository->fetchAll('descripcion'); + return $view->render($response, 'ventas.pies.cuotas', compact('pie', 'venta', 'bancos', 'estados', 'ventaRepository')); } }