Desistir venta

This commit is contained in:
2023-12-21 18:45:47 -03:00
parent 93431e41b3
commit 80a6bf1535
8 changed files with 221 additions and 62 deletions

View File

@ -29,6 +29,7 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) {
$app->get('[/]', [Ventas::class, 'pie']);
});
$app->get('/escriturar[/]', [Ventas::class, 'escriturar']);
$app->get('/desistir[/]', [Ventas::class, 'desistir']);
$app->get('/edit[/]', [Ventas::class, 'edit']);
$app->get('[/]', [Ventas::class, 'show']);
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));

View File

@ -22,9 +22,10 @@ $app->group('/ventas', function($app) {
$app->post('[/]', [Ventas::class, 'proyecto']);
});
$app->group('/venta/{venta_id}', function($app) {
$app->get('/unidades', [Ventas::class, 'unidades']);
$app->get('/comentarios', [Ventas::class, 'comentarios']);
$app->post('/escriturar', [Ventas::class, 'escriturar']);
$app->get('/unidades[/]', [Ventas::class, 'unidades']);
$app->get('/comentarios[/]', [Ventas::class, 'comentarios']);
$app->post('/escriturar[/]', [Ventas::class, 'escriturar']);
$app->post('/desistir[/]', [Ventas::class, 'desistir']);
$app->post('[/]', [Ventas::class, 'edit']);
$app->get('[/]', [Ventas::class, 'get']);
});

View File

@ -12,7 +12,14 @@
if (!Object.hasOwn(options['headers'], 'Authorization')) {
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}'
}
return fetch(url, options)
return fetch(url, options).then(response => {
if (response.ok) {
return response
}
throw new Error(JSON.stringify({code: response.status, message: response.statusText, url}))
}).catch(error => {
console.error(error)
})
}
const calendar_date_options = {
type: 'date',

View File

@ -0,0 +1,75 @@
@extends('layout.base')
@section('page_content')
<div class="ui container">
<h1 class="ui header">
Desistir - {{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}">{{$venta->propiedad()->summary()}}</a>
</h1>
<div class="ui list">
<div class="item">
<div class="header">Valor Pagado</div>
<div class="content">
{{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}}
<div class="ui left pointing small label">
{{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
</div>
</div>
</div>
<div class="item">
<div class="header">
Multa Estandar
<div class="ui left pointing small label">5%</div>
</div>
<div class="content">
{{$format->pesos($venta->valor * 0.05 * $UF->get())}}
</div>
</div>
</div>
<form class="ui form" id="desistir_form">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" />
</div>
</div>
</div>
<div class="three wide field">
<label for="devolucion">Devolución [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="devolucion" />
</div>
</div>
<button class="ui button">Desistir</button>
</form>
</div>
@endsection
@push('page_scripts')
<script>
$(document).ready(() => {
$('#fecha').calendar(calendar_date_options)
$('#desistir_form').submit(event => {
event.preventDefault()
const body = new FormData(event.currentTarget)
const fecha = $('#fecha').calendar('get date')
body.set('fecha', fecha.toISOString())
const url = '{{$urls->api}}/venta/{{$venta->id}}/desistir'
fetchAPI(url, {method: 'post', body}).then(response => {
if (!response) {
return
}
response.json().then(json => {
if (json.desistida) {
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
}
})
})
return false
})
})
</script>
@endpush