From ac52305002003f8e97d3504c5db52e02ffe00ad8 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Thu, 21 Dec 2023 21:06:38 -0300 Subject: [PATCH] Editar desistimiento venta --- app/resources/routes/04_ventas.php | 1 + app/resources/routes/api/ventas/pagos.php | 3 +- .../views/ventas/desistida.blade.php | 78 +++++++++++++++++ app/src/Controller/API/Ventas/Pagos.php | 85 +++++++++++++++++++ app/src/Controller/Ventas.php | 6 ++ app/src/Controller/Ventas/Pagos.php | 52 ------------ app/src/Model/Venta/Pago.php | 2 +- 7 files changed, 173 insertions(+), 54 deletions(-) create mode 100644 app/resources/views/ventas/desistida.blade.php create mode 100644 app/src/Controller/API/Ventas/Pagos.php diff --git a/app/resources/routes/04_ventas.php b/app/resources/routes/04_ventas.php index 83487cb..8ab4684 100644 --- a/app/resources/routes/04_ventas.php +++ b/app/resources/routes/04_ventas.php @@ -30,6 +30,7 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) { }); $app->get('/escriturar[/]', [Ventas::class, 'escriturar']); $app->get('/desistir[/]', [Ventas::class, 'desistir']); + $app->get('/desistida[/]', [Ventas::class, 'desistida']); $app->get('/edit[/]', [Ventas::class, 'edit']); $app->get('[/]', [Ventas::class, 'show']); })->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); diff --git a/app/resources/routes/api/ventas/pagos.php b/app/resources/routes/api/ventas/pagos.php index 6addcda..dc60160 100644 --- a/app/resources/routes/api/ventas/pagos.php +++ b/app/resources/routes/api/ventas/pagos.php @@ -1,5 +1,5 @@ group('/pagos', function($app) { $app->get('/pendientes', [Pagos::class, 'para_pendientes']); @@ -9,4 +9,5 @@ $app->group('/pagos', function($app) { $app->group('/pago/{pago_id:[0-9]+}', function($app) { $app->put('/depositar[/]', [Pagos::class, 'depositar']); $app->put('/abonar[/]', [Pagos::class, 'abonar']); + $app->post('[/]', [Pagos::class, 'edit']); }); diff --git a/app/resources/views/ventas/desistida.blade.php b/app/resources/views/ventas/desistida.blade.php new file mode 100644 index 0000000..4d394df --- /dev/null +++ b/app/resources/views/ventas/desistida.blade.php @@ -0,0 +1,78 @@ +@extends('layout.base') + +@section('page_content') +
+

+ Desistida - {{$venta->proyecto()->descripcion}} - + + {{$venta->propiedad()->summary()}} + +

+
+
+ +
+
+ + +
+
+
+
+ +
+
$
+ +
+
+
+
+@endsection + +@push('page_scripts') + +@endpush diff --git a/app/src/Controller/API/Ventas/Pagos.php b/app/src/Controller/API/Ventas/Pagos.php new file mode 100644 index 0000000..4e5548f --- /dev/null +++ b/app/src/Controller/API/Ventas/Pagos.php @@ -0,0 +1,85 @@ +getParsedBody(); + $output = [ + 'input' => $body, + 'pago_id' => $pago_id, + 'pago' => null + ]; + try { + $pago = $pagoRepository->fetchById($pago_id); + if (isset($body['fecha'])) { + $fecha = new DateTimeImmutable($body['fecha']); + $body['fecha'] = $fecha->format('Y-m-d'); + } + $output['pago'] = $pagoRepository->edit($pago, $body); + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } + // NOT IMPLEMENTED + public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface + { + $body = $request->getBody(); + $json = json_decode($body->getContents()); + $date = new DateTimeImmutable($json->fecha); + $response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented'])); + return $response->withHeader('Content-Type', 'application/json'); + } + // NOT IMPLEMENTED + public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface + { + $body = $request->getBody(); + $json = json_decode($body->getContents()); + $date = new DateTimeImmutable($json->fecha); + $response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented'])); + return $response->withHeader('Content-Type', 'application/json'); + } + public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface + { + $pagos = $pagoService->getPendientes(); + $pagos_pendientes = []; + foreach ($pagos as $pago) { + $pagos_pendientes []= [ + 'id' => $pago->id + ]; + } + return $this->withJson($response, ['pagos' => $pagos_pendientes, 'total' => count($pagos_pendientes)]); + } + public function para_abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface + { + $pagos = $pagoService->getDepositados(); + $pagos_depositados = []; + foreach ($pagos as $pago) { + $pagos_depositados []= [ + 'id' => $pago->id + ]; + } + return $this->withJson($response, ['pagos' => $pagos_depositados, 'total' => count($pagos_depositados)]); + } + public function rebotes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface + { + $pagos = $pagoService->getRebotes(); + $rebotes = []; + foreach ($pagos as $pago) { + $rebotes []= [ + 'id' => $pago->id + ]; + } + return $this->withJson($response, ['pagos' => $rebotes, 'total' => count($rebotes)]); + } +} diff --git a/app/src/Controller/Ventas.php b/app/src/Controller/Ventas.php index b037f69..4060dc4 100644 --- a/app/src/Controller/Ventas.php +++ b/app/src/Controller/Ventas.php @@ -114,4 +114,10 @@ class Ventas $venta = $ventaService->getById($venta_id); return $view->render($response, 'ventas.desistir', compact('venta')); } + public function desistida(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, + View $view, int $venta_id): ResponseInterface + { + $venta = $ventaService->getById($venta_id); + return $view->render($response, 'ventas.desistida', compact('venta')); + } } diff --git a/app/src/Controller/Ventas/Pagos.php b/app/src/Controller/Ventas/Pagos.php index 882c39e..e8de649 100644 --- a/app/src/Controller/Ventas/Pagos.php +++ b/app/src/Controller/Ventas/Pagos.php @@ -13,56 +13,4 @@ class Pagos { return $view->render($response, 'ventas.pagos.pendientes'); } - public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface - { - $body = $request->getBody(); - $json = json_decode($body->getContents()); - $date = new DateTimeImmutable($json->fecha); - $response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented'])); - return $response->withHeader('Content-Type', 'application/json'); - } - public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface - { - $body = $request->getBody(); - $json = json_decode($body->getContents()); - $date = new DateTimeImmutable($json->fecha); - $response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented'])); - return $response->withHeader('Content-Type', 'application/json'); - } - public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface - { - $pagos = $pagoService->getPendientes(); - $pagos_pendientes = []; - foreach ($pagos as $pago) { - $pagos_pendientes []= [ - 'id' => $pago->id - ]; - } - $response->getBody()->write(json_encode(['pagos' => $pagos_pendientes, 'total' => count($pagos_pendientes)])); - return $response->withHeader('Content-Type', 'application/json'); - } - public function para_abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface - { - $pagos = $pagoService->getDepositados(); - $pagos_depositados = []; - foreach ($pagos as $pago) { - $pagos_depositados []= [ - 'id' => $pago->id - ]; - } - $response->getBody()->write(json_encode(['pagos' => $pagos_depositados, 'total' => count($pagos_depositados)])); - return $response->withHeader('Content-Type', 'application/json'); - } - public function rebotes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface - { - $pagos = $pagoService->getRebotes(); - $rebotes = []; - foreach ($pagos as $pago) { - $rebotes []= [ - 'id' => $pago->id - ]; - } - $response->getBody()->write(json_encode(['pagos' => $rebotes, 'total' => count($rebotes)])); - return $response->withHeader('Content-Type', 'application/json'); - } } diff --git a/app/src/Model/Venta/Pago.php b/app/src/Model/Venta/Pago.php index 9b2e1ba..8beda1e 100644 --- a/app/src/Model/Venta/Pago.php +++ b/app/src/Model/Venta/Pago.php @@ -34,7 +34,7 @@ class Pago extends Model 'banco' => $this->banco ?? '', 'tipo_pago' => $this->tipoPago ?? '', 'identificador' => $this->identificador ?? '', - 'fecha' => $this->fecha->format('Y-m-d H:i:S') ?? '', + 'fecha' => $this->fecha->format('Y-m-d H:i:s') ?? '', 'uf' => $this->uf ?? 1, 'pagador' => $this->pagador ?? '', 'asociado' => $this->asociado ?? ''