0.1.0
This commit is contained in:
170
public/js/ventas/list.js
Normal file
170
public/js/ventas/list.js
Normal file
@ -0,0 +1,170 @@
|
||||
const ventas = {
|
||||
url: '',
|
||||
id_proyecto: '',
|
||||
id_ventas: '',
|
||||
setup: function() {
|
||||
sendGet(this.url).then(response => {
|
||||
const formatters = {
|
||||
pesos: Intl.NumberFormat('es-CL', {style: 'decimal', useGrouping: true}),
|
||||
uf: Intl.NumberFormat('es-CL', {style: 'decimal', useGrouping: true, minimumFractionDigits: 2, maximumFractionDigits: 2})
|
||||
}
|
||||
const p = new Proyecto(response.proyecto)
|
||||
p.set().formatters(formatters)
|
||||
p.draw().title($(this.id_proyecto))
|
||||
p.draw().ventas($(this.id_ventas))
|
||||
})
|
||||
}
|
||||
}
|
||||
class Proyecto {
|
||||
constructor({id, descripcion, ventas}) {
|
||||
this.id = id
|
||||
this.descripcion = descripcion
|
||||
this.set().ventas(ventas)
|
||||
this.formatters = {
|
||||
uf: null
|
||||
}
|
||||
}
|
||||
set() {
|
||||
return {
|
||||
ventas: ventas => {
|
||||
this.ventas = ventas.map(el => {
|
||||
return new Venta(el)
|
||||
})
|
||||
},
|
||||
formatters: formatters => {
|
||||
this.formatters = formatters
|
||||
this.ventas.forEach(v => {
|
||||
v.set().formatters(formatters)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
draw() {
|
||||
return {
|
||||
title: parent => {
|
||||
parent.append(
|
||||
$('<a></a>').attr('href', _urls.base + '/proyecto/' + this.id).html(this.descripcion + ' [' + this.ventas.length + ']')
|
||||
)
|
||||
},
|
||||
ventas: tbody => {
|
||||
this.ventas.forEach(venta => {
|
||||
venta.draw().row(tbody)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class Venta {
|
||||
constructor({id, propiedad, propietario, fecha, valor, estado}) {
|
||||
this.id = id
|
||||
this.unidades = ''
|
||||
this.set().unidades(propiedad)
|
||||
this.propiedad = propiedad
|
||||
this.superficie = 0
|
||||
this.set().superficie(propiedad)
|
||||
this.tipologia = ''
|
||||
this.set().tipologia(propiedad)
|
||||
this.propietario = ''
|
||||
this.set().propietario(propietario)
|
||||
this.fecha = fecha
|
||||
this.valor = valor
|
||||
this.estado = ''
|
||||
this.set().estado(estado)
|
||||
this.formatters = {
|
||||
uf: null
|
||||
}
|
||||
}
|
||||
set() {
|
||||
return {
|
||||
unidades: propiedad => {
|
||||
const departamentos = propiedad.unidades.filter(u => {
|
||||
return (u.tipo.descripcion === 'departamento')
|
||||
}).map(u => {
|
||||
return u.descripcion
|
||||
}).join('-')
|
||||
let bodegas = []
|
||||
let estacionamientos = propiedad.unidades.filter(u => {
|
||||
return (u.tipo.descripcion === 'estacionamiento')
|
||||
}).map(u => {
|
||||
if (u.descripcion.includes('B')) {
|
||||
const e = u.descripcion.split('B')
|
||||
while (e.length > 1) {
|
||||
bodegas.push(e.pop().replace(' ', '').replace('-', ','))
|
||||
}
|
||||
return e[0].replace(' ', '').replace(',', '').replace('-', ',')
|
||||
}
|
||||
return u.descripcion.replace(' ', '').replace('-', ',').replace('y ', ',')
|
||||
}).sort((a, b) => {
|
||||
return parseInt(a) - parseInt(b)
|
||||
})
|
||||
if (estacionamientos.length > 0) {
|
||||
estacionamientos = ' - E' + estacionamientos.join(',').replace(/(,\s)*$/g, '')
|
||||
} else {
|
||||
estacionamientos = ''
|
||||
}
|
||||
bodegas = [...(bodegas.filter(el => el !== '')), ...(propiedad.unidades.filter(u => {
|
||||
return (u.tipo.descripcion === 'bodega')
|
||||
}).map(u => {
|
||||
return u.descripcion.replace(' ', '').replace('-', ',')
|
||||
}))].sort((a, b) => {
|
||||
return parseInt(a) - parseInt(b)
|
||||
}).filter(el => el !== '')
|
||||
if (bodegas.length > 0) {
|
||||
bodegas = ' - B' + bodegas.join(',').replace(/(,\s)*$/g, '')
|
||||
} else {
|
||||
bodegas = ''
|
||||
}
|
||||
this.unidades = departamentos + estacionamientos + bodegas
|
||||
},
|
||||
superficie: propiedad => {
|
||||
const unidad = propiedad.unidades[0]
|
||||
this.superficie = unidad.proyectoTipoUnidad.superficie.vendible
|
||||
},
|
||||
tipologia: propiedad => {
|
||||
const unidad = propiedad.unidades[0]
|
||||
this.tipologia = unidad.proyectoTipoUnidad.tipologia.abreviacion
|
||||
},
|
||||
propietario: propietario => {
|
||||
this.propietario = propietario.nombreCompleto
|
||||
},
|
||||
estado: estado => {
|
||||
this.estado = estado.estado.descripcion.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase(); })
|
||||
},
|
||||
formatters: formatters => {
|
||||
this.formatters = formatters
|
||||
}
|
||||
}
|
||||
}
|
||||
draw() {
|
||||
return {
|
||||
row: parent => {
|
||||
parent.append(
|
||||
$('<tr></tr>').append(
|
||||
$('<td></td>').append(
|
||||
$('<a></a>')
|
||||
.attr('href', _urls.base + '/venta/' + this.id)
|
||||
.html(this.unidades)
|
||||
.append('<span class="glyphicon glyphicon-chevron-right small"></span>')
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<a></a>')
|
||||
.attr('href', _urls.base + '/search/' + encodeURIComponent(this.propietario))
|
||||
.html(this.propietario + ' <span class="glyphicon glyphicon-search small"></span>')
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').html(this.formatters.uf.format(this.valor) + ' UF')
|
||||
).append(
|
||||
$('<td></td>').html(this.tipologia + ' (' + this.formatters.uf.format(this.superficie) + ' m²)')
|
||||
).append(
|
||||
$('<td></td>').html(this.formatters.uf.format(this.valor / this.superficie) + ' UF/m²')
|
||||
).append(
|
||||
$('<td></td>').html(new Date(this.fecha.date).toLocaleDateString('es-CL'))
|
||||
).append(
|
||||
$('<td></td>').html(this.estado)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user