This commit is contained in:
2023-11-29 22:21:46 -03:00
parent 9991b7c6a3
commit 17f93dcd34
6 changed files with 93 additions and 0 deletions

View File

@ -26,6 +26,7 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) {
$app->group('/cuotas', function($app) {
$app->get('[/]', [Ventas::class, 'cuotas']);
});
$app->get('[/]', [Ventas::class, 'pie']);
});
$app->get('/edit[/]', [Ventas::class, 'edit']);
$app->get('[/]', [Ventas::class, 'show']);

View File

@ -0,0 +1,6 @@
<?php
use Incoviba\Controller\API\Ventas\Pies;
$app->group('/pie/{pie_id}', function($app) {
$app->post('/edit[/]', [Pies::class, 'edit']);
});

View File

@ -0,0 +1,46 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h2 class="ui header">
Pie -
{{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}">{{$venta->propiedad()->summary()}}</a>
</h2>
<form class="ui form" id="edit_pie">
<div class="three wide field">
<label for="valor">Valor</label>
<div class="ui right labeled input">
<input type="text" name="valor" id="valor" value="{{$venta->formaPago()->pie->valor}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="three wide field">
<label for="cuotas"># Cuotas</label>
<input type="number" name="cuotas" id="cuotas" value="{{$venta->formaPago()->pie->cuotas}}" />
</div>
<button class="ui button">Editar</button>
</form>
</div>
@endsection
@push('page_scripts')
<script>
$(document).ready(() => {
$('#edit_pie').submit(event => {
event.preventDefault()
const data = new FormData(event.currentTarget)
fetchAPI('{{$urls->api}}/ventas/pie/{{$venta->formaPago()->pie->id}}/edit', {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
}
}).then(json => {
if (json.edited) {
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
}
})
return false
})
})
</script>
@endpush

View File

@ -0,0 +1,31 @@
<?php
namespace Incoviba\Controller\API\Ventas;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Incoviba\Controller\API\{withJson, emptyBody};
use Incoviba\Controller\withRedis;
use Incoviba\Common\Implement\Exception\{EmptyRedis, EmptyResult};
use Incoviba\Service;
class Pies
{
use withRedis, withJson, emptyBody;
public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService, int $pie_id): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'pie_id' => $pie_id,
'input' => $body,
'edited' => false
];
error_log(var_export($output,true).PHP_EOL,3,'/logs/pies');
try {
$pie = $pieService->getById($pie_id);
$pieService->edit($pie, (array) $body);
$output['edited'] = true;
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -71,6 +71,11 @@ class Ventas
}
return $view->render($response, 'ventas.propiedades.edit', compact('propiedad', 'proyecto', 'tiposUnidades', 'unidades', 'venta'));
}
public function pie(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface
{
$venta = $service->getById($venta_id);
return $view->render($response, 'ventas.pies.edit', compact('venta'));
}
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Region $regionRepository, Repository\Proyecto $proyectoRepository): ResponseInterface
{
$regiones = $regionRepository->fetchAll();

View File

@ -27,4 +27,8 @@ class Pie
{
return $this->cuotaService->add($data);
}
public function edit(Model\Venta\Pie $pie, array $data): Model\Venta\Pie
{
return $this->pieRepository->edit($pie, $data);
}
}