diff --git a/app/resources/routes/api/ventas.php b/app/resources/routes/api/ventas.php index 894128d..cd58933 100644 --- a/app/resources/routes/api/ventas.php +++ b/app/resources/routes/api/ventas.php @@ -24,5 +24,6 @@ $app->group('/ventas', function($app) { $app->group('/venta/{venta_id}', function($app) { $app->get('/unidades', [Ventas::class, 'unidades']); $app->get('/comentarios', [Ventas::class, 'comentarios']); + $app->post('[/]', [Ventas::class, 'edit']); $app->get('[/]', [Ventas::class, 'get']); }); diff --git a/app/resources/views/ventas/edit.blade.php b/app/resources/views/ventas/edit.blade.php index 8596b77..09c52fb 100644 --- a/app/resources/views/ventas/edit.blade.php +++ b/app/resources/views/ventas/edit.blade.php @@ -2,7 +2,10 @@ @section('page_content')
-

Editar Venta

+

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

@@ -29,66 +32,53 @@ @push('page_scripts') @endpush diff --git a/app/resources/views/ventas/propiedades/edit.blade.php b/app/resources/views/ventas/propiedades/edit.blade.php index 80ce28d..e54d5d9 100644 --- a/app/resources/views/ventas/propiedades/edit.blade.php +++ b/app/resources/views/ventas/propiedades/edit.blade.php @@ -158,10 +158,10 @@ return } const old_value = this.unidades[idx].valor - if (old_value === parseFloat(value)) { + if (old_value === parseFloat(valor)) { return } - const url = '{{$urls->api}}/ventas/propiedades/unidad/' + id + '/edit' + const url = '{{$urls->api}}/ventas/propiedades/unidad/' + pid + '/edit' const data = new FormData() data.set('valor', valor) return fetchAPI(url, {method: 'post', body: data}).then(response => { diff --git a/app/src/Controller/API/Ventas.php b/app/src/Controller/API/Ventas.php index 770cc12..ab29f17 100644 --- a/app/src/Controller/API/Ventas.php +++ b/app/src/Controller/API/Ventas.php @@ -189,6 +189,23 @@ class Ventas } return $this->withJson($response, $output); } + public function edit(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $ventaRepository, int $venta_id): ResponseInterface + { + $body = $request->getParsedBody(); + $output = [ + 'venta_id' => $venta_id, + 'input' => $body, + 'edited' => false + ]; + try { + $venta = $ventaRepository->fetchById($venta_id); + $body['valor_uf'] = $body['valor']; + $body['fecha'] = (new DateTimeImmutable($body['fecha']))->format('Y-m-d'); + $ventaRepository->edit($venta, $body); + $output['edited'] = true; + } catch (EmptyResult) {} + return $this->withJson($response, $output); + } public function unidades(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, Service\Venta\Unidad $unidadService, int $venta_id): ResponseInterface { diff --git a/app/src/Model/Venta.php b/app/src/Model/Venta.php index fa2610c..a9f8098 100644 --- a/app/src/Model/Venta.php +++ b/app/src/Model/Venta.php @@ -75,10 +75,10 @@ class Venta extends Ideal\Model if (!isset($this->valor_util)) { $sum = $this->valor; $sum -= array_reduce($this->propiedad()->estacionamientos(), function(float $sum, Venta\Unidad $unidad) { - return $unidad->precio($this->fecha)->valor; + return $unidad->valor ?? $unidad->precio($this->fecha)->valor; }, 0); $sum -= array_reduce($this->propiedad()->bodegas(), function(float $sum, Venta\Unidad $unidad) { - return $unidad->precio($this->fecha)->valor; + return $unidad->valor ?? $unidad->precio($this->fecha)->valor; }, 0); $this->valor_util = $sum; }