Editar propiedad en venta
This commit is contained in:
@ -244,6 +244,9 @@
|
||||
return {
|
||||
price: (id, value) => {
|
||||
const idx = this.unidades.findIndex(unidad => unidad.pu_id === id)
|
||||
if (idx === -1) {
|
||||
return
|
||||
}
|
||||
const old_value = this.unidades[idx].precio
|
||||
if (old_value === parseFloat(value)) {
|
||||
return
|
||||
|
@ -2,12 +2,18 @@
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2>Editar Propiedad - {{$proyecto->descripcion}} {{$propiedad->summary()}}</h2>
|
||||
<h2 class="ui header">
|
||||
Editar Propiedad - {{$proyecto->descripcion}}
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}">
|
||||
{{$propiedad->summary()}}
|
||||
</a>
|
||||
</h2>
|
||||
<table class="ui table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tipo</th>
|
||||
<th>Unidad</th>
|
||||
<th>Valor</th>
|
||||
<th class="right aligned">
|
||||
<button class="ui small green circular icon button" id="add_unidad">
|
||||
<i class="plus icon"></i>
|
||||
@ -15,13 +21,19 @@
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody id="unidades">
|
||||
@foreach($propiedad->unidades as $unidad)
|
||||
<tr>
|
||||
<td>{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}</td>
|
||||
<td>{{$unidad->descripcion}}</td>
|
||||
<td>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="precio{{$unidad->pu_id}}" class="precio" data-pid="{{$unidad->pu_id}}" value="{{($unidad->valor > 0) ? $unidad->valor : $unidad->precio($venta->fecha)}}" />
|
||||
<div class="ui basic label">UF</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="right aligned">
|
||||
<button class="ui small red circular icon button remove_unidad" data-id="{{$unidad->id}}">
|
||||
<button class="ui small red circular icon button remove_unidad" data-pid="{{$unidad->pu_id}}">
|
||||
<i class="remove icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
@ -54,7 +66,19 @@
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
const unidades = {
|
||||
const propiedad = {
|
||||
unidades: [
|
||||
@foreach($propiedad->unidades as $unidad)
|
||||
{
|
||||
id: {{$unidad->id}},
|
||||
tipo: '{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}',
|
||||
descripcion: '{{$unidad->descripcion}}',
|
||||
pid: {{$unidad->pu_id}},
|
||||
valor: {{($unidad->valor > 0) ? $unidad->valor : $unidad->precio($venta->fecha)}}
|
||||
},
|
||||
@endforeach
|
||||
],
|
||||
tipos: {
|
||||
@foreach($tiposUnidades as $tipoUnidad)
|
||||
{{$tipoUnidad->id}}: [
|
||||
@foreach($unidades as $unidad)
|
||||
@ -68,37 +92,106 @@
|
||||
@endforeach
|
||||
],
|
||||
@endforeach
|
||||
}
|
||||
function changeTipoUnidad(tipo_unidad_id) {
|
||||
$('#unidad').dropdown('change values', unidades[tipo_unidad_id].sort((a, b) => a.text.padStart(4, '0').localeCompare(b.text.padStart(4, '0'))))
|
||||
}
|
||||
function addUnidad() {
|
||||
},
|
||||
changeTipoUnidad: function(tipo_unidad_id) {
|
||||
$('#unidad').dropdown('change values', this.tipos[tipo_unidad_id].sort((a, b) => a.text.padStart(4, '0').localeCompare(b.text.padStart(4, '0'))))
|
||||
},
|
||||
addUnidad: function() {
|
||||
$('#add_modal').modal('show')
|
||||
}
|
||||
function removeUnidad(unidad_id) {
|
||||
},
|
||||
removeUnidad: function(unidad_id) {
|
||||
console.debug(unidad_id)
|
||||
},
|
||||
updatePrecio: function(pid, valor) {
|
||||
const idx = this.unidades.findIndex(unidad => unidad.pid === pid)
|
||||
if (idx === -1) {
|
||||
return
|
||||
}
|
||||
$(document).ready(() => {
|
||||
$('#add_unidad').click(event => {
|
||||
addUnidad()
|
||||
const old_value = this.unidades[idx].valor
|
||||
if (old_value === parseFloat(value)) {
|
||||
return
|
||||
}
|
||||
const url = '{{$urls->api}}/ventas/propiedades/unidad/' + id + '/edit'
|
||||
const data = new FormData()
|
||||
data.set('valor', value)
|
||||
return fetchAPI(url, {method: 'post', body: data}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(json => {
|
||||
if (!json.edited) {
|
||||
return
|
||||
}
|
||||
const idx = this.unidades.findIndex(unidad => unidad.pid === json.propiedad_unidad_id)
|
||||
this.unidades[idx].valor = parseFloat(json.input.valor)
|
||||
this.draw()
|
||||
})
|
||||
},
|
||||
draw: function() {
|
||||
const tbody = $('#unidades')
|
||||
tbody.html('')
|
||||
this.unidades.forEach(unidad => {
|
||||
const row = $('<tr></tr>').append(
|
||||
$('<td></td>').html(unidad.tipo)
|
||||
).append(
|
||||
$('<td></td>').html(unidad.descripcion)
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<div></div>').addClass('ui right labeled input').append(
|
||||
$('<input />').addClass('precio').attr('type', 'text').attr('data-pid', unidad.pid).attr('value', unidad.valor)
|
||||
).append(
|
||||
$('<div></div>').addClass('ui basic label').html('UF')
|
||||
)
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').addClass('right aligned').append(
|
||||
$('<button></button>').addClass('ui small red circular icon button remove_unidad').attr('data-pid', unidad.pid).append(
|
||||
$('<i></i>').addClass('remove icon')
|
||||
)
|
||||
)
|
||||
)
|
||||
tbody.append(row)
|
||||
})
|
||||
$('.price').change(event => {
|
||||
const pid = $(event.currentTarget).data('pid')
|
||||
const val = $(event.currentTarget).val()
|
||||
this.updatePrecio(pid, val)
|
||||
})
|
||||
$('.remove_unidad').click(event => {
|
||||
const unidad_id = $(event.currentTarget).data('id')
|
||||
removeUnidad(unidad_id)
|
||||
const unidad_id = $(event.currentTarget).data('pid')
|
||||
this.removeUnidad(unidad_id)
|
||||
})
|
||||
},
|
||||
setup: function() {
|
||||
$('#add_unidad').click(event => {
|
||||
this.addUnidad()
|
||||
})
|
||||
$('.remove_unidad').click(event => {
|
||||
const unidad_id = $(event.currentTarget).data('pid')
|
||||
this.removeUnidad(unidad_id)
|
||||
})
|
||||
$('#add_modal').modal()
|
||||
const tipo = $('#tipo')
|
||||
tipo.dropdown()
|
||||
tipo.change(event => {
|
||||
changeTipoUnidad(tipo.val())
|
||||
this.changeTipoUnidad(tipo.val())
|
||||
})
|
||||
$('#unidad').dropdown()
|
||||
changeTipoUnidad(tipo.val())
|
||||
this.changeTipoUnidad(tipo.val())
|
||||
$('#add_form').submit(event => {
|
||||
event.preventDefault()
|
||||
tipo.model('hide')
|
||||
return false
|
||||
})
|
||||
$('.precio').change(event => {
|
||||
const pid = $(event.currentTarget).data('pid')
|
||||
const val = $(event.currentTarget).val()
|
||||
this.updatePrecio(pid, val)
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
propiedad.setup()
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -16,6 +16,7 @@
|
||||
<th class="center aligned">Piso</th>
|
||||
<th class="right aligned">Metros vendibles</th>
|
||||
<th class="right aligned">Precio</th>
|
||||
<th class="right aligned">Valor Venta</th>
|
||||
<th class="right aligned">UF/m²</th>
|
||||
<th class="center aligned">Orientacion</th>
|
||||
</tr>
|
||||
@ -41,6 +42,9 @@
|
||||
<td class="right aligned">
|
||||
{{$format->ufs($unidad->precio($venta->fecha)->valor)}}
|
||||
</td>
|
||||
<td class="right aligned">
|
||||
{{$format->ufs($unidad->valor)}}
|
||||
</td>
|
||||
<td class="right aligned">
|
||||
@if ($unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento')
|
||||
{{$format->number($unidad->precio($venta->fecha)->valor / $unidad->proyectoTipoUnidad->vendible(), 2)}} UF/m²
|
||||
|
@ -69,7 +69,7 @@ class Ventas
|
||||
$tiposUnidades []= $unidad->proyectoTipoUnidad->tipoUnidad;
|
||||
}
|
||||
}
|
||||
return $view->render($response, 'ventas.propiedades.edit', compact('propiedad', 'proyecto', 'tiposUnidades', 'unidades', 'venta_id'));
|
||||
return $view->render($response, 'ventas.propiedades.edit', compact('propiedad', 'proyecto', 'tiposUnidades', 'unidades', 'venta'));
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Region $regionRepository, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
|
Reference in New Issue
Block a user