Merge branch 'develop' into feature/cierres

This commit is contained in:
Juan Pablo Vial
2025-02-24 21:36:35 -03:00
19 changed files with 420 additions and 65 deletions

View File

@ -9,3 +9,7 @@ $app->group('/direcciones', function($app) {
$app->post('/find[/]', [Direcciones::class, 'findComunas']);
});
});
$app->group('/direccion/{direccion_id:[0-9]+}', function($app) {
$app->post('/edit[/]', [Direcciones::class, 'edit']);
$app->get('[/]', [Direcciones::class, 'get']);
});

View File

@ -2,7 +2,10 @@
use Incoviba\Controller\API\Regiones;
//$app->group('/regiones', function($app) {});
$app->group('/regiones', function($app) {
$app->get('[/]', Regiones::class);
});
$app->group('/region/{region_id}', function($app) {
$app->get('/provincias[/]', [Regiones::class, 'provincias']);
$app->get('/comunas[/]', [Regiones::class, 'comunas']);
});

View File

@ -15,7 +15,7 @@
<table class="ui striped table">
<tr>
<td>Dirección</td>
<td>{{$proyecto->direccion()}}</td>
<td>{{$proyecto->direccion()}} <a href="#" id="edit_direccion_button"><i class="small edit icon"></i></a></td>
</tr>
<tr>
<td>Inmobiliaria</td>
@ -137,6 +137,7 @@
</div>
@endsection
@include('proyectos.show.edit_direccion')
@include('layout.body.scripts.chartjs')
@push('page_scripts')
@ -485,6 +486,11 @@
ventas.setup({id_ventas: '#ventas', id_stock: '#stock', id_proyeccion: '#proyeccion',
id_chart_general: '#chart_venta_general', id_chart_tipologias: '#chart_venta_tipologia',
id_chart_velocidad: '#chart_venta_velocidad'})
document.getElementById('edit_direccion_button').addEventListener('click', event => {
event.preventDefault()
$('#edit_direccion_modal').modal('show')
})
})
</script>
@endpush

View File

@ -0,0 +1,136 @@
<div class="ui modal" id="edit_direccion_modal">
<div class="header">
Editar Dirección
</div>
<div class="content">
<form class="ui form" id="edit_direccion_form">
<input type="hidden" name="id" />
<div class="fields">
<div class="field">
<label>Calle</label>
<input type="text" name="calle" value="{{ $proyecto->direccion()->calle }}" />
</div>
<div class="field">
<label>Número</label>
<input type="text" name="numero" value="{{ $proyecto->direccion()->numero }}" />
</div>
<div class="field">
<label>Extra</label>
<input type="text" name="extra" value="{{ $proyecto->direccion()->extra }}" />
</div>
</div>
<div class="fields">
<div class="field">
<label>Comuna</label>
<div class="ui search selection dropdown" id="comuna">
<input type="hidden" name="comuna" />
<i class="dropdown icon"></i>
<div class="default text">Comuna</div>
<div class="menu"></div>
</div>
</div>
<div class="field">
<label>Región</label>
<div class="ui search selection dropdown" id="region">
<input type="hidden" name="region" />
<i class="dropdown icon"></i>
<div class="default text">Región</div>
<div class="menu"></div>
</div>
</div>
</div>
</form>
</div>
<div class="actions">
<div class="ui black deny button">
Cancelar
</div>
<div class="ui green ok button">
Guardar
</div>
</div>
</div>
@push('page_scripts')
<script>
function submitForm() {
const form = document.getElementById('edit_direccion_form')
const body = new FormData(form)
const url = '{{$urls->api}}/direccion/{{ $proyecto->direccion()->id }}/edit'
const method = 'post'
APIClient.fetch(url, {method, body}).then(response => {
if (response.ok) {
return response.json().then(json => {
if (json.success) {
window.location.reload()
}
})
}
})
}
function fetchComunas(region_id) {
const url = `{{ $urls->api }}/region/${region_id}/comunas`
APIClient.fetch(url).then(response => {
if (!response.ok) {
return;
}
return response.json().then(json => {
const dropdown = $('#comuna')
const values = []
json.comunas.forEach(comuna => {
values.push({
name: comuna.descripcion,
value: comuna.id,
text: comuna.descripcion
})
})
dropdown.dropdown('change values', values)
if (json.region_id === {{ $proyecto->direccion()->comuna->provincia->region->id }}) {
dropdown.dropdown('set selected', {{ $proyecto->direccion()->comuna->id }})
}
})
})
}
function fetchRegiones() {
const url = '{{ $urls->api }}/regiones'
APIClient.fetch(url).then(response => {
if (!response.ok) {
return;
}
return response.json().then(json => {
const dropdown = $('#region')
const values = []
json.regiones.forEach(region => {
values.push({
name: region.descripcion,
value: region.id,
text: region.descripcion
})
})
dropdown.dropdown({
values,
onChange: (value, text, $choice) => {
fetchComunas(value)
}
})
$('#comuna').dropdown()
dropdown.dropdown('set selected', {{ $proyecto->direccion()->comuna->provincia->region->id }})
})
})
}
$(document).ready(function() {
fetchRegiones()
$('#edit_direccion_modal').modal({
onApprove: function() {
submitForm()
}
})
document.getElementById('edit_direccion_form').addEventListener('submit', event => {
event.preventDefault()
submitForm()
return false
})
})
</script>
@endpush

View File

@ -251,12 +251,21 @@
event.preventDefault()
const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar'
const body = new FormData(event.currentTarget)
body.set('fecha', $('#fecha').calendar('get date').toISOString())
if (body.get('fecha_pago') !== '') {
body.set('fecha_pago', $('#fecha_pago').calendar('get date').toISOString())
const fecha = $('#fecha').calendar('get date')
body.set('fecha', [fecha.getFullYear(), fecha.getMonth()+1, fecha.getDate()].join('-'))
const $fechaPago = $('#fecha_pago')
if ($fechaPago.length > 0) {
const fechaPago = $fechaPago.calendar('get date')
if (fechaPago !== null) {
body.set('fecha_pago', [fechaPago.getFullYear(), fechaPago.getMonth()+1, fechaPago.getDate()].join('-'))
}
}
if (body.get('fecha_reajuste') !== '') {
body.set('fecha_reajuste', $('#fecha_reajuste').calendar('get date').toISOString())
const $fechaReajuste = $('#fecha_reajuste')
if ($fechaReajuste.length > 0) {
const fechaReajuste = $fechaReajuste.calendar('get date')
if (fechaReajuste !== null) {
body.set('fecha_reajuste', [fechaReajuste.getFullYear(), fechaReajuste.getMonth()+1, fechaReajuste.getDate()].join('-'))
}
}
fetchAPI(url, {method: 'post', body}).then(response => {
if (response.ok) {

View File

@ -37,7 +37,7 @@
<label for="valor">Valor</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="valor" value="{{$venta->formaPago()->escritura->pago->valor}}" />
<input type="text" name="valor" id="valor" value="{{$venta->formaPago()->escritura->pago->valor}}" />
</div>
</div>
<div class="three wide field">
@ -62,9 +62,9 @@
function editEscritura() {
const url = '{{$urls->api}}/ventas/escritura/{{$venta->id}}/edit'
const data = new FormData()
data.set('venta', {{$venta->id}})
const fecha = $('#fecha').calendar('get date')
data.set('fecha', fecha.toISOString())
data.set('valor', $('#valor').val())
data.set('estado', $('#estado').dropdown('get value'))
return fetchAPI(url, {method: 'post', body: data}).then(response => {
if (response.ok) {
@ -78,10 +78,11 @@
})
}
$(document).ready(() => {
calendar_date_options.initialDate = new Date({{$venta->currentEstado()->fecha->format('Y, m-1, j')}})
calendar_date_options.initialDate = new Date({{$venta->formaPago()->escritura->pago->currentEstado->fecha->format('Y, m-1, j')}})
$('#fecha').calendar(calendar_date_options)
$('#estado').dropdown()
$('#estado').dropdown('set selected', '{{$venta->currentEstado()->id}}')
const $estado = $('#estado')
$estado.dropdown()
$estado.dropdown('set selected', '{{$venta->formaPago()->escritura->pago->currentEstado->tipoEstadoPago->id}}')
$('#edit_form').submit(event => {
event.preventDefault()
editEscritura()

View File

@ -82,7 +82,7 @@
new Unidad({
id: {{$unidad->id}},
tipo: '{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}',
descripcion: '{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}} {{ $unidad->descripcion }} (UF {{ number_format($unidad->precio($venta->currentEstado()->fecha)->valor, 2) }})',
descripcion: '{{ $unidad->descripcion }}',
prorrateo: {{$unidad->prorrateo}},
propiedad_unidad_id: {{$unidad->pu_id}},
valor: {{($unidad->valor > 0) ? $unidad->valor : $unidad->precio($venta->currentEstado()->fecha)->valor}}
@ -96,7 +96,7 @@
@if ($terreno->fecha != null) fecha: new Date('{{$terreno->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}'),
@else fecha: null,
@endif
valor: {{($terreno->valor ?? 0) * (1+$ipc)}}
valor: {{($terreno->valor ?? 0) * (1 + $ipc)}}
},
facturas: []
}
@ -110,9 +110,9 @@
this.venta.props.facturas.facturas[{{$factura->index - 1}}] = new Factura({
id: {{ $factura->id }},
venta: this.venta.props,
proporcion: {{ $factura->proporcion }},
index: {{$factura->index}},
fecha: new Date('{{$factura->fecha->format('Y-m-d')}}'),
proporcion: {{$factura->proporcion}},
emisor: {
rut: '{{$factura->venta->proyecto()->inmobiliaria()->rut}}',
nombre: '{{$factura->venta->proyecto()->inmobiliaria()->razon}}',
@ -137,7 +137,7 @@
unidad: new Unidad({
id: {{$unidad->unidad->id}},
tipo: '{{ucwords($unidad->unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}',
descripcion: '{{ucwords($unidad->unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}} {{ $unidad->unidad->descripcion }} (UF {{ number_format(array_values(array_filter($venta->propiedad()->unidades, function($uni) use ($unidad, $factura) {return $uni->id === $unidad->unidad->id;}))[0]->precio($venta->currentEstado()->fecha)->valor * $factura->proporcion, 2) }})',
descripcion: '{{ $unidad->unidad->descripcion }}',
prorrateo: {{$unidad->prorrateo}},
propiedad_unidad_id: {{ array_values(array_filter($venta->propiedad()->unidades, function($uni) use ($unidad) {return $uni->id === $unidad->unidad->id;}))[0]->pu_id }},
valor: {{$unidad->precio}}
@ -150,7 +150,7 @@
],
detalle: {
base: {{ $factura->base() }},
terreno: {{ $factura->terreno * $factura->proporcion }},
terreno: {{ $factura->terreno * $factura->proporcion * $factura->prorrateo }},
neto: {{ $factura->neto() }},
iva: {{ $factura->iva() }},
bruto: {{ $factura->bruto() }},

View File

@ -5,6 +5,10 @@
venta: null,
index: 0,
proporcion: 0,
terreno: {
fecha: null,
valor: 0
},
emisor: {
rut: '',
nombre: '',
@ -50,6 +54,9 @@
get saved() {
return this.props.id > 0
}
get prorrateo() {
return this.props.unidades.reduce((sum, unidad) => sum + unidad.prorrateo, 0)
}
draw() {
return {
divider: () => {
@ -186,7 +193,7 @@
return unidadesData.join("\n")
},
unidad: ({unidad, no, classes, formatters}) => {
const descuento = this.props.detalle.terreno * unidad.prorrateo
const descuento = this.props.terreno.valor * unidad.prorrateo * this.props.proporcion
const bruto = unidad.precio - descuento
const neto = bruto / 1.19
const data = [
@ -240,6 +247,20 @@
return row.join('')
},
totales: ({formatters}) => {
let tooltips = {
neto: null,
iva: null,
total: null
}
if (this.props.total.neto !== this.props.detalle.neto) {
tooltips.neto = ` data-tooltip="No coinciden netos! Promesa: ${formatters.pesos.format(this.props.detalle.neto)} - Unidades: ${formatters.pesos.format(this.props.total.neto)}"`
}
if (this.props.total.iva !== this.props.detalle.iva) {
tooltips.iva = ` data-tooltip="No coinciden ivas! Promesa: ${formatters.pesos.format(this.props.detalle.iva)} - Unidades: ${formatters.pesos.format(this.props.total.iva)}"`
}
if (this.props.total.total !== this.props.detalle.total) {
tooltips.total = ` data-tooltip="No coinciden totales! Promesa: ${formatters.pesos.format(this.props.detalle.total)} - Unidades: ${formatters.pesos.format(this.props.total.total)}"`
}
return [
'<div class="row">',
'<div class="ten wide column"></div>',
@ -253,7 +274,7 @@
'<tbody>',
'<tr>',
'<td class="grey">Monto Neto</td>',
'<td class="right aligned" id="neto">'+formatters.pesos.format(this.props.total.neto)+'</td>',
`<td class="right aligned${this.props.total.neto !== this.props.detalle.neto ? ' red' : ''}"${this.props.total.neto !== this.props.detalle.neto ? tooltips.neto : ''} id="neto">${formatters.pesos.format(this.props.total.neto)}</td>`,
'</tr>',
'<tr>',
'<td class="grey">Monto Exento</td>',
@ -261,11 +282,11 @@
'</tr>',
'<tr>',
'<td class="grey">19% IVA</td>',
'<td class="right aligned" id="iva">'+formatters.pesos.format(this.props.total.iva)+'</td>',
`<td class="right aligned${this.props.total.iva !== this.props.detalle.iva ? ' red' : ''}"${this.props.total.iva !== this.props.detalle.iva ? tooltips.iva : ''} id="iva">${formatters.pesos.format(this.props.total.iva)}</td>`,
'</tr>',
'<tr>',
'<td class="grey">Monto Total</td>',
'<td class="right aligned"><strong id="total">'+formatters.pesos.format(this.props.total.total)+'</strong></td>',
`<td class="right aligned${(this.props.total.total !== this.props.detalle.total) ? ' red' : ''}"${(this.props.total.total !== this.props.detalle.total) ? tooltips.total : ''}><strong id="total">${formatters.pesos.format(this.props.total.total)}</strong></td>`,
'</tr>',
'</tbody>',
'</table>',
@ -364,12 +385,10 @@
this.props.uf.valor = venta.props.uf.valor
this.update().propietario(venta.props.propietarios.find(propietario => propietario.props.index === this.props.index))
this.update().unidades(venta.props.unidades)
this.props.total.total = this.props.detalle.total = venta.props.valor * this.props.proporcion * venta.props.uf.valor
this.update().detalle(venta.props.facturas.terreno.valor * venta.prorrateo)
this.props.total.exento = this.props.detalle.terreno
this.props.total.iva = this.props.detalle.iva
this.props.total.neto = this.props.unidades.reduce((sum, unidad) => sum + unidad.precio, 0)
this.props.detalle.total = venta.props.valor * this.props.proporcion * venta.props.uf.valor
this.update().detalle(venta.props.facturas.terreno.valor * this.prorrateo)
this.props.detalle.descuento = venta.prorrateo * this.props.proporcion
this.update().total()
},
detalle: terreno => {
this.props.detalle.terreno = terreno * this.props.proporcion
@ -378,14 +397,20 @@
this.props.detalle.iva = this.props.detalle.neto * 0.19
this.props.detalle.base = this.props.detalle.neto + this.props.detalle.terreno
},
total: () => {
this.props.total.exento = this.props.detalle.terreno
this.props.total.neto = (this.props.unidades.reduce((sum, unidad) => sum + unidad.precio, 0) - this.props.total.exento) / 1.19
this.props.total.iva = this.props.total.neto * 0.19
this.props.total.total = this.props.total.neto + this.props.total.iva + this.props.total.exento
},
unidades: unidades => {
this.props.unidades = []
unidades.forEach(unidad => {
this.props.unidades.push({
unidad: unidad,
descripcion: unidad.changeDescripcion(this.props.proporcion || 1),
precio: unidad.props.valor * this.props.uf.valor * this.props.proporcion,
prorrateo: unidad.props.prorrateo * this.props.proporcion
precio: unidad.props.valor * this.props.uf.valor,
prorrateo: unidad.props.prorrateo
})
})
},

View File

@ -14,7 +14,7 @@
}
changeDescripcion(proporcion = 1) {
return this.descripcion = [this.props.tipo, this.props.descripcion, `[UF ${facturas.formatters.ufs.format(this.props.valor * proporcion)}]`].join(' ')
return this.descripcion = [this.props.tipo, this.props.descripcion, `(UF ${facturas.formatters.ufs.format(this.props.valor * proporcion)})`].join(' ')
}
update() {
return {

View File

@ -403,6 +403,7 @@
venta: this.props,
index: propietario.props.index,
proporcion: propietario.props.proporcion,
terreno: this.props.facturas.terreno,
emisor: {
rut: this.props.inmobiliaria.rut,
nombre: this.props.inmobiliaria.nombre,