Search
This commit is contained in:
7
app/resources/routes/97_search.php
Normal file
7
app/resources/routes/97_search.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Search;
|
||||
|
||||
$app->group('/search', function($app) {
|
||||
$app->get('[/{query}[/{tipo}[/]]]', Search::class);
|
||||
$app->post('[/]', Search::class);
|
||||
});
|
4
app/resources/routes/api/search.php
Normal file
4
app/resources/routes/api/search.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Search;
|
||||
|
||||
$app->post('/search', [Search::class, 'query']);
|
220
app/resources/views/search.blade.php
Normal file
220
app/resources/views/search.blade.php
Normal file
@ -0,0 +1,220 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h1>Búsqueda</h1>
|
||||
|
||||
<form id="search_form" class="ui form" action="{{$urls->base}}/search" method="post">
|
||||
<div class="field">
|
||||
<div class="ui fluid input">
|
||||
<input type="text" name="query" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui search selection dropdown" id="tipo">
|
||||
<input type="hidden" name="tipo" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Tipo</div>
|
||||
<div class="menu">
|
||||
<div class="item" data-value="*" data-selected="true">Cualquiera</div>
|
||||
@foreach (['departamento', 'estacionamiento', 'bodega', 'propietario', 'precio_venta', 'proyecto', 'pago', 'unidad'] as $value)
|
||||
<div class="item" data-value="{{$value}}">{{ucwords(str_replace('_', ' ', $value))}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button" type="submit">Buscar</button>
|
||||
</form>
|
||||
<div id="results"></div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.head.styles.datatables')
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
class Row
|
||||
{
|
||||
proyecto
|
||||
unidad
|
||||
venta
|
||||
|
||||
constructor({proyecto, unidad}) {
|
||||
this.proyecto = proyecto
|
||||
this.unidad = unidad
|
||||
}
|
||||
draw() {
|
||||
const tipo = this.unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
let unidad = tipo.charAt(0).toUpperCase() + tipo.slice(1) + ' ' + this.unidad.descripcion
|
||||
let propietario = ''
|
||||
let fecha = ''
|
||||
let fecha_entrega = ''
|
||||
if (typeof this.venta !== 'undefined') {
|
||||
const dateFormatter = new Intl.DateTimeFormat('es-CL', {dateStyle: 'medium'})
|
||||
unidad = $('<a></a>').attr('href', '{{$urls->base}}/venta/' + this.venta.id).html(unidad)
|
||||
if (!this.venta.current_estado.tipo_estado_venta.activa) {
|
||||
unidad.html(unidad.html() + ' (I)')
|
||||
}
|
||||
propietario = $('<a></a>')
|
||||
.attr('href','{{$urls->base}}/search/' + encodeURIComponent(this.venta.propietario.nombre_completo) + '/propietario')
|
||||
.html(this.venta.propietario.nombre_completo)
|
||||
fecha = dateFormatter.format(new Date(this.venta.fecha))
|
||||
if (typeof this.venta.entrega !== 'undefined') {
|
||||
fecha_entrega = dateFormatter.format(new Date(this.venta.entrega.fecha))
|
||||
}
|
||||
} else {
|
||||
unidad += '<i class="ban icon"></i>'
|
||||
}
|
||||
|
||||
return $('<tr></tr>').append(
|
||||
$('<td></td>').append(
|
||||
$('<a></a>').attr('href', '{{$urls->base}}/proyecto/' + this.proyecto.id).html(this.proyecto.descripcion)
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').append(unidad)
|
||||
).append(
|
||||
$('<td></td>').append(propietario)
|
||||
).append(
|
||||
$('<td></td>').addClass('right aligned').html(Math.round(this.unidad.proyecto_tipo_unidad.superficie * 100) / 100 + ' m²')
|
||||
).append(
|
||||
$('<td></td>').addClass('right aligned').html(this.unidad.precio)
|
||||
).append(
|
||||
$('<td></td>').html(fecha)
|
||||
).append(
|
||||
$('<td></td>').html(fecha_entrega)
|
||||
)
|
||||
}
|
||||
}
|
||||
const results = {
|
||||
id: '',
|
||||
data: [],
|
||||
table: null,
|
||||
get: function() {
|
||||
return {
|
||||
results: () => {
|
||||
if ($("[name='query']").val().length < 1) {
|
||||
return
|
||||
}
|
||||
this.draw().loading()
|
||||
const data = new FormData(document.getElementById('search_form'))
|
||||
const uri = '{{$urls->api}}/search'
|
||||
this.data = []
|
||||
return fetch(uri, {method: 'post', body: data}).then(response => {
|
||||
this.draw().clear()
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (typeof data.results !== 'undefined' && data.results.length > 0) {
|
||||
data.results.forEach(row => {
|
||||
if (typeof row.proyecto_tipo_unidad === 'undefined') {
|
||||
const r = new Row({unidad: row.propiedad.departamentos[0], proyecto: row.proyecto})
|
||||
r.venta = row
|
||||
this.data.push(r)
|
||||
} else {
|
||||
this.data.push(new Row({unidad: row, proyecto: row.proyecto_tipo_unidad.proyecto}))
|
||||
}
|
||||
})
|
||||
this.draw().table()
|
||||
return
|
||||
}
|
||||
this.draw().empty()
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
return {
|
||||
clear: () => {
|
||||
$(this.id).html('')
|
||||
},
|
||||
separator: () => {
|
||||
this.draw().clear()
|
||||
$(this.id).append(
|
||||
$('<div></div>').addClass('ui horizontal divider').html('Resultados')
|
||||
)
|
||||
},
|
||||
loading: () => {
|
||||
this.draw().separator()
|
||||
$(this.id).append(
|
||||
$('<div></div>').addClass('ui active centered inline loader')
|
||||
)
|
||||
},
|
||||
table: () => {
|
||||
const parent = $(this.id)
|
||||
this.draw().separator()
|
||||
|
||||
if (this.table !== null) {
|
||||
this.table.clear()
|
||||
.draw()
|
||||
.destroy()
|
||||
this.table = null
|
||||
}
|
||||
|
||||
const table = $('<table></table>').addClass('ui table')
|
||||
const thead = this.draw().head()
|
||||
const tbody = $('<tbody></tbody>')
|
||||
|
||||
this.data.forEach(row => {
|
||||
tbody.append(row.draw())
|
||||
})
|
||||
table.append(thead).append(tbody)
|
||||
parent.append(table)
|
||||
|
||||
this.table = new DataTable(table)
|
||||
},
|
||||
head: () => {
|
||||
return $('<thead></thead>').append(
|
||||
$('<tr></tr>').append(
|
||||
$('<th></th>').html('Proyecto')
|
||||
).append(
|
||||
$('<th></th>').html('Unidad')
|
||||
).append(
|
||||
$('<th></th>').html('Propietario')
|
||||
).append(
|
||||
$('<th></th>').html('Superficie')
|
||||
).append(
|
||||
$('<th></th>').html('Valor')
|
||||
).append(
|
||||
$('<th></th>').html('Fecha Venta')
|
||||
).append(
|
||||
$('<th></th>').html('Fecha Entrega')
|
||||
)
|
||||
)
|
||||
},
|
||||
empty: () => {
|
||||
this.draw().separator()
|
||||
$(this.id).append(
|
||||
$('<div></div>').addClass('ui icon info message').append(
|
||||
$('<i></i>').addClass('meh outline icon')
|
||||
).append(
|
||||
$('<div></div>').addClass('content').html('No se han encontrado resultados.')
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
setup: function(id) {
|
||||
this.id = id
|
||||
this.get().results()
|
||||
|
||||
$('#search_form').submit(event => {
|
||||
event.preventDefault()
|
||||
this.get().results()
|
||||
return false
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
$('#tipo').dropdown().dropdown('set selected', '*')
|
||||
@if (trim($post) !== '')
|
||||
$("[name='query']").val('{{$post}}')
|
||||
@elseif (trim($query) !== '')
|
||||
$("[name='query']").val('{{$query}}')
|
||||
@endif
|
||||
@if (trim($tipo) !== '')
|
||||
$('#tipo').dropdown('set selected', '{{$tipo}}')
|
||||
@endif
|
||||
results.setup('#results')
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -19,7 +19,7 @@
|
||||
<td class="right aligned">
|
||||
{{$format->pesos($credito->pago->valor)}}
|
||||
</td>
|
||||
<td id="credito_pago" class="{{$credito->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado' ? 'warning' : ($credito->pago->currentEstado->tipoEstado->descripcion === 'depositado' ? 'positive' : '')}}">
|
||||
<td id="credito_pago" class="{{$credito->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado' ? 'warning' : ($credito->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado' ? 'positive' : '')}}">
|
||||
<span class="text">{{$credito->pago->currentEstado->fecha->format('d-m-Y')}}</span>
|
||||
@if ($credito->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado')
|
||||
<a href="javascript: depositar({row_id: '#credito_pago', pago_id: {{$credito->pago->id}}});" title="Depositar">
|
||||
|
@ -9,7 +9,7 @@
|
||||
</a>
|
||||
{{$venta->propietario()->rut()}}
|
||||
<div class="meta">
|
||||
{{$venta->propietario()->datos->direccion}}
|
||||
{{$venta->propietario()->datos->direccion ?? ''}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user