Mostrar alertas en inicio

This commit is contained in:
2023-10-19 18:20:37 -03:00
parent c2a3192b32
commit 02e1f3e091
25 changed files with 915 additions and 225 deletions

View File

@ -75,48 +75,46 @@
@push('page_scripts')
<script type="text/javascript">
class Unidad {
data = {
id: 0,
nombre: '',
fecha: '',
precio: 0,
superficie: 0,
tipo: '',
linea: 0
}
id
nombre
fecha
precio
superficie
tipo
linea
constructor({id, nombre, fecha, precio, superficie, tipo, linea}) {
this.data.id = id
this.data.nombre = nombre
this.data.fecha = fecha
this.data.precio = precio
this.data.superficie = superficie
this.data.tipo = tipo
this.data.linea = linea
this.id = id
this.nombre = nombre
this.fecha = fecha
this.precio = precio
this.superficie = superficie
this.tipo = tipo
this.linea = linea
}
unitario() {
return this.data.precio / this.data.superficie
get unitario() {
return this.precio / this.superficie
}
draw(formatter) {
const date = new Date(this.data.fecha)
const date = new Date(this.fecha)
const dateFormatter = new Intl.DateTimeFormat('es-CL')
return $('<tr></tr>').addClass('unidad').attr('data-linea', this.data.linea).append(
$('<td></td>').html(this.data.nombre)
return $('<tr></tr>').addClass('unidad').attr('data-linea', this.linea).append(
$('<td></td>').html(this.nombre)
).append(
$('<td></td>')
).append(
$('<td></td>').html(dateFormatter.format(date))
).append(
$('<td></td>').html(formatter.format(this.data.precio) + ' UF')
$('<td></td>').html(formatter.format(this.precio) + ' UF')
).append(
$('<td></td>').html(formatter.format(this.unitario()) + ' UF/m²')
$('<td></td>').html(formatter.format(this.unitario) + ' UF/m²')
).append(
$('<td></td>').append(
$('<button></button>').addClass('ui tiny green icon button add_unidad')
.attr('data-id', this.data.id)
.attr('data-tipo', this.data.tipo)
.attr('data-unidad', this.data.nombre).append(
.attr('data-id', this.id)
.attr('data-tipo', this.tipo)
.attr('data-unidad', this.nombre).append(
$('<i></i>').addClass('plus icon')
).click(precios.actions().add().unidad)
)
@ -124,36 +122,36 @@
}
}
class Linea {
data = {
id: 0,
nombre: '',
orientacion: '',
superficie: 0,
unidades: [],
}
id
nombre
orientacion
superficie
unidades
constructor({id, nombre, orientacion, superficie}) {
this.data.id = id
this.data.nombre = nombre
this.data.orientacion = orientacion
this.data.superficie = superficie
this.id = id
this.nombre = nombre
this.orientacion = orientacion
this.superficie = superficie
this.unidades = []
}
precio() {
get precio() {
let sum = 0
this.data.unidades.forEach(unidad => {
sum += unidad.data.precio
this.unidades.forEach(unidad => {
sum += unidad.precio
})
return sum / this.data.unidades.length
return sum / this.unidades.length
}
unitario() {
return this.precio() / this.data.superficie
get unitario() {
return this.precio / this.superficie
}
add(data) {
if (this.data.id !== data.unidad.subtipo) {
if (this.id !== data.unidad.subtipo) {
return
}
let unidad = this.data.unidades.find(unidad => unidad.data.id === data.unidad.id)
let unidad = this.unidades.find(unidad => unidad.id === data.unidad.id)
if (typeof unidad !== 'undefined') {
return
}
@ -163,28 +161,28 @@
nombre: data.unidad.descripcion,
fecha: data.estado_precio.fecha,
precio: data.valor,
superficie: this.data.superficie,
superficie: this.superficie,
tipo: tipo.charAt(0).toUpperCase() + tipo.slice(1),
linea: this.data.id
linea: this.id
})
this.data.unidades.push(unidad)
this.unidades.push(unidad)
}
draw(formatter) {
const row1 = $('<tr></tr>').attr('data-id', this.data.id).attr('data-status', 'closed').append(
$('<td></td>').addClass('linea').append($('<strong></strong>').html(this.data.nombre)).append(
const row1 = $('<tr></tr>').attr('data-id', this.id).attr('data-status', 'closed').append(
$('<td></td>').addClass('linea').append($('<strong></strong>').html(this.nombre)).append(
$('<i></i>').addClass('right caret icon')
)
).append(
$('<td></td>').addClass('linea').append($('<strong></strong>').html(this.data.orientacion))
$('<td></td>').addClass('linea').append($('<strong></strong>').html(this.orientacion))
).append(
$('<td></td>').addClass('linea')
).append(
$('<td></td>').addClass('linea').append($('<strong></strong>').html(formatter.format(this.precio()) + ' UF'))
$('<td></td>').addClass('linea').append($('<strong></strong>').html(formatter.format(this.precio) + ' UF'))
).append(
$('<td></td>').addClass('linea').append($('<strong></strong>').html(formatter.format(this.unitario()) + ' UF/m²'))
$('<td></td>').addClass('linea').append($('<strong></strong>').html(formatter.format(this.unitario) + ' UF/m²'))
).append(
$('<td></td>').append(
$('<button></button>').addClass('ui tiny green icon button add_linea').attr('data-id', this.data.id).append(
$('<button></button>').addClass('ui tiny green icon button add_linea').attr('data-id', this.id).append(
$('<i></i>').addClass('plus icon')
).click(precios.actions().add().linea)
)
@ -192,90 +190,93 @@
const output = [
row1
]
this.data.unidades.forEach(unidad => {
this.unidades.forEach(unidad => {
output.push(unidad.draw(formatter))
})
return output
}
}
class Tipologia {
data = {
id: 0,
tipo: '',
nombre: '',
descripcion: '',
lineas: [],
superficie: 0,
}
id
tipo
nombre
descripcion
lineas
superficie
constructor({id, tipo, nombre, descripcion, superficie}) {
this.data.id = id
this.data.tipo = tipo
this.data.nombre = nombre
this.data.descripcion = descripcion
this.data.superficie = superficie
this.id = id
this.tipo = tipo
this.nombre = nombre
this.descripcion = descripcion
this.superficie = superficie
this.lineas = []
}
count() {
return this.data.lineas.reduce((sum, linea) => {
return sum + linea.data.unidades.length
get count() {
return this.lineas.reduce((sum, linea) => {
return sum + linea.unidades.length
}, 0)
}
precio() {
get precio() {
let sum = 0
this.data.lineas.forEach(linea => {
sum += linea.precio()
this.lineas.forEach(linea => {
sum += linea.precio
})
return sum / this.data.lineas.length
return sum / this.lineas.length
}
unitario() {
return this.precio() / this.data.superficie
get unitario() {
return this.precio / this.superficie
}
add(data) {
if (this.data.id !== data.unidad.proyecto_tipo_unidad.id) {
if (this.id !== data.unidad.proyecto_tipo_unidad.id) {
return
}
let linea = this.data.lineas.find(linea => linea.data.id === data.unidad.subtipo)
if (this.data.lineas.length === 0 || typeof linea === 'undefined') {
let linea = this.lineas.find(linea => linea.id === data.unidad.subtipo)
if (this.lineas.length === 0 || typeof linea === 'undefined') {
linea = new Linea({
id: data.unidad.subtipo,
nombre: 'Linea ' + data.unidad.subtipo,
orientacion: data.unidad.orientacion,
superficie: data.unidad.proyecto_tipo_unidad.vendible
})
this.data.lineas.push(linea)
this.lineas.push(linea)
}
linea.add(data)
}
draw(formatter) {
const output = []
const row1 = $('<tr></tr>').attr('data-status', 'closed').attr('data-id', this.data.id)
const row1 = $('<tr></tr>').attr('data-status', 'closed').attr('data-id', this.id)
row1.append(
$('<td></td>').addClass('show-unidades').html(this.data.tipo).append(
$('<td></td>').addClass('show-unidades').html(this.tipo).append(
$('<i></i>').addClass('right caret icon')
)
).append(
$('<td></td>').addClass('show-unidades').html(this.data.nombre)
$('<td></td>').addClass('show-unidades').html(this.nombre)
).append(
$('<td></td>').addClass('show-unidades').html(this.data.descripcion)
$('<td></td>').addClass('show-unidades').html(this.descripcion)
).append(
$('<td></td>').addClass('show-unidades').html(this.data.lineas.map(linea => linea.data.id).sort((a, b) => parseInt(a) - parseInt(b)).join(' - '))
$('<td></td>').addClass('show-unidades').html(this.lineas.map(linea => linea.id).sort((a, b) => parseInt(a) - parseInt(b)).join(' - '))
).append(
$('<td></td>').addClass('show-unidades').html(formatter.format(this.data.superficie) + ' m²')
$('<td></td>').addClass('show-unidades').html(formatter.format(this.superficie) + ' m²')
).append(
$('<td></td>').addClass('show-unidades').html(this.count())
$('<td></td>').addClass('show-unidades').html(this.count)
).append(
$('<td></td>').addClass('show-unidades').html(formatter.format(this.precio()) + ' UF')
$('<td></td>').addClass('show-unidades').html(formatter.format(this.precio) + ' UF')
).append(
$('<td></td>').addClass('show-unidades').html(formatter.format(this.unitario()) + ' UF/m²')
$('<td></td>').addClass('show-unidades').html(formatter.format(this.unitario) + ' UF/m²')
).append(
$('<td></td>').append(
$('<button></button>').addClass('ui tiny green icon button add_tipologia').attr('data-id', this.data.id).attr('data-tipologia', this.data.nombre).append(
$('<button></button>').addClass('ui tiny green icon button add_tipologia').attr('data-id', this.id).attr('data-tipologia', this.nombre).append(
$('<i></i>').addClass('plus icon')
).click(precios.actions().add().tipologia)
)
)
const row2 = $('<tr></tr>').addClass('unidades').attr('data-tipo', this.data.id)
const row2 = $('<tr></tr>').addClass('unidades').attr('data-tipo', this.id)
const tbody = $('<tbody></tbody>')
this.data.lineas.forEach(linea => {
this.lineas.forEach(linea => {
linea.draw(formatter).forEach(row => {
tbody.append(row)
})
@ -308,6 +309,7 @@
return output
}
}
const precios = {
ids: {
list: '',
@ -379,7 +381,7 @@
add: function() {
return {
precio: data => {
let tipologia = this.data.precios.find(tipologia => tipologia.data.id === data.unidad.proyecto_tipo_unidad.id)
let tipologia = this.data.precios.find(tipologia => tipologia.id === data.unidad.proyecto_tipo_unidad.id)
if (this.data.precios.length === 0 || typeof tipologia === 'undefined') {
const tipo = data.unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
tipologia = new Tipologia({
@ -495,13 +497,16 @@
const unidades = $(".unidades[data-tipo='" + id + "']")
if (status === 'closed') {
unidades.show()
row.attr('data-status', 'open')
row.find('.caret.icon').removeClass('right').addClass('down')
return
}
unidades.find('.linea').data('status', 'closed')
unidades.find('.linea').parent().attr('data-status', 'closed')
unidades.find('.linea').find('.caret.icon').removeClass('down').addClass('right')
unidades.find('.unidad').hide()
unidades.hide()
row.attr('data-status', 'closed')
row.find('.caret.icon').removeClass('down').addClass('right')
},
@ -513,11 +518,13 @@
const unidades = $(".unidad[data-linea='" + id + "']")
if (status === 'closed') {
unidades.show()
row.attr('data-status', 'open')
row.find('.caret.icon').removeClass('right').addClass('down')
return
}
unidades.hide()
row.attr('data-status', 'closed')
row.find('.caret.icon').removeClass('down').addClass('right')
}
@ -576,7 +583,13 @@
},
}
},
setup: function() {
setup: function({list, proyectos, buttons_up, buttons_refresh, buttons_add}) {
this.ids.list = list
this.ids.proyectos = proyectos
this.ids.buttons.up = buttons_up
this.ids.buttons.refresh = buttons_refresh
this.ids.buttons.add = buttons_add
$(this.ids.buttons.up).click(this.actions().up)
$(this.ids.buttons.refresh).click(this.actions().refresh)
$(this.ids.buttons.add).click(this.actions().add().list)
@ -584,7 +597,6 @@
this.draw().proyectos()
}
}
const list_modal = {
ids: {
modal: '',
@ -644,7 +656,15 @@
$(this.ids.modal).find("input[name='type']").val(this.data.type)
$(this.ids.modal).find("input[name='id']").val(this.data.id)
},
setup: function() {
setup: function({modal, title, fields_type, fields_id, fields_calendar, fields_valor, button}) {
this.ids.modal = modal
this.ids.title = title
this.ids.fields.type = fields_type
this.ids.fields.id = fields_id
this.ids.fields.calendar = fields_calendar
this.ids.fields.valor = fields_valor
this.ids.button = button
$(this.ids.modal).modal('hide')
$(this.ids.modal).find('.icon.button').find('.close.icon').parent().click(this.actions().close)
@ -656,21 +676,22 @@
}
$(document).ready(() => {
precios.ids.list = '#list'
precios.ids.proyectos = '#proyectos'
precios.ids.buttons.up = '#up_button'
precios.ids.buttons.refresh = '#refresh_button'
precios.ids.buttons.add = '#add_button'
precios.setup()
list_modal.ids.modal = '#list_modal'
list_modal.ids.title = '#modal_title'
list_modal.ids.fields.type = "input[name='type']"
list_modal.ids.fields.id = "input[name='id']"
list_modal.ids.fields.calendar = '#fecha'
list_modal.ids.fields.valor = '#valor'
list_modal.ids.button = '#send'
list_modal.setup()
precios.setup({
list: '#list',
proyectos: '#proyectos',
buttons_up: '#up_button',
buttons_refresh: '#refresh_button',
buttons_add: '#add_button'
})
list_modal.setup({
modal: '#list_modal',
title: '#modal_title',
fields_type: "input[name='type']",
fields_id: "input[name='id']",
fields_calendar: '#fecha',
fields_valor: '#valor',
button: '#send'
})
})
</script>
@endpush