Promociones en misma tabla para tipo
This commit is contained in:
@ -47,6 +47,136 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class GroupedTableHandler extends TableHandler {
|
||||||
|
promotions = {
|
||||||
|
names: new Set(),
|
||||||
|
values: []
|
||||||
|
}
|
||||||
|
process() {
|
||||||
|
return {
|
||||||
|
prices: prices => {
|
||||||
|
let promotions = {}
|
||||||
|
prices.map(price => price.promotions).forEach(promotionArray => {
|
||||||
|
promotionArray.forEach(p => {
|
||||||
|
if (!Object.hasOwn(promotions, p.name)) {
|
||||||
|
promotions[p.name] = {
|
||||||
|
name: p.name,
|
||||||
|
type: p.type,
|
||||||
|
amount: [],
|
||||||
|
final: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
promotions[p.name].amount.push(p.amount)
|
||||||
|
promotions[p.name].final.push(p.final)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return promotions
|
||||||
|
},
|
||||||
|
promotions: () => {
|
||||||
|
return {
|
||||||
|
names: promotions => {
|
||||||
|
Object.keys(promotions).forEach(name => {
|
||||||
|
this.add().promotion().name(name)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
values: ({promotions, formatters}) => {
|
||||||
|
const temp = Object.values(promotions)
|
||||||
|
if (temp.length > 0) {
|
||||||
|
const data = temp.map(p => {
|
||||||
|
return {
|
||||||
|
name: p.name,
|
||||||
|
type: p.type,
|
||||||
|
amount: {
|
||||||
|
min: Math.min(...p.amount),
|
||||||
|
max: Math.max(...p.amount),
|
||||||
|
desv: Stat.standardDeviation(p.amount),
|
||||||
|
mean: Stat.mean(p.amount)
|
||||||
|
},
|
||||||
|
final: {
|
||||||
|
min: Math.min(...p.final),
|
||||||
|
max: Math.max(...p.final),
|
||||||
|
desv: Stat.standardDeviation(p.final),
|
||||||
|
mean: Stat.mean(p.final)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.add().promotion().values({promotions: data, formatters})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.promotions.values.push([])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add() {
|
||||||
|
return {
|
||||||
|
promotion: () => {
|
||||||
|
return {
|
||||||
|
name: name => {
|
||||||
|
this.promotions.names.add(name)
|
||||||
|
},
|
||||||
|
values: ({promotions, formatters}) => {
|
||||||
|
this.promotions.values.push(promotions.map(promotion => {
|
||||||
|
const amount_tooltip = [
|
||||||
|
`Min: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.min) : formatters.percent.format(promotion.amount.min)}`,
|
||||||
|
`Max: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.max) : formatters.percent.format(promotion.amount.max)}`,
|
||||||
|
`Desv: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.desv) : formatters.percent.format(promotion.amount.desv)}`
|
||||||
|
].join("\n").replaceAll(' ', ' ')
|
||||||
|
const final_tooltip = [
|
||||||
|
`Min: UF ${formatters.ufs.format(promotion.final.min)}`,
|
||||||
|
`Max: UF ${formatters.ufs.format(promotion.final.max)}`,
|
||||||
|
`Desv: UF ${formatters.ufs.format(promotion.final.desv)}`
|
||||||
|
].join("\n").replaceAll(' ', ' ')
|
||||||
|
return {
|
||||||
|
name: promotion.name,
|
||||||
|
value: [
|
||||||
|
`<td class="right aligned"><span data-tooltip="${amount_tooltip}" data-position="right center" data-variation="wide multiline">${promotion.type === 1 ? formatters.ufs.format(promotion.amount.mean) : formatters.percent.format(promotion.amount.mean)}</td>`,
|
||||||
|
`<td class="right aligned"><span data-tooltip="${final_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(promotion.final.mean)}</td></td>`,
|
||||||
|
].join("\n")
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
build() {
|
||||||
|
return {
|
||||||
|
promotions: (table, tbody) => {
|
||||||
|
if (this.promotions.names.size > 0) {
|
||||||
|
const title = document.getElementById(this.ids.promotions)
|
||||||
|
title.innerHTML = this.promotions.names.size > 0 ? Array.from(this.promotions.names)[0] : ''
|
||||||
|
title.setAttribute('colspan', '2')
|
||||||
|
if (this.promotions.names.size > 1) {
|
||||||
|
const thead = table.querySelector('thead')
|
||||||
|
Array.from(this.promotions.names).slice(1).forEach(name => {
|
||||||
|
thead.insertAdjacentHTML('beforeend', `<th class="right aligned" style="text-decoration: overline" colspan="2">${name}</th>`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const trs = tbody.querySelectorAll('tr')
|
||||||
|
this.promotions.values.forEach((row, i) => {
|
||||||
|
const tr = trs[i]
|
||||||
|
const td = tr.querySelector('td.promotions')
|
||||||
|
if (row.length === 0) {
|
||||||
|
td.setAttribute('colspan', 2 * this.promotions.names.size)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
td.remove()
|
||||||
|
this.promotions.names.forEach(name => {
|
||||||
|
const index = row.findIndex(r => r.name === name)
|
||||||
|
if (index === -1) {
|
||||||
|
tr.insertAdjacentHTML('beforeend', '<td colspan="2"></td>')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tr.insertAdjacentHTML('beforeend', row[index].value)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
@endprepend
|
@endprepend
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<th class="right aligned" style="text-decoration: overline">Precio Base</th>
|
<th class="right aligned" style="text-decoration: overline">Precio Base</th>
|
||||||
<th class="right aligned" style="text-decoration: overline">Comisión</th>
|
<th class="right aligned" style="text-decoration: overline">Comisión</th>
|
||||||
<th class="right aligned" style="text-decoration: overline">Precio Operador</th>
|
<th class="right aligned" style="text-decoration: overline">Precio Operador</th>
|
||||||
<th class="right aligned" style="text-decoration: overline">Precio Final</th>
|
<th class="center aligned" style="text-decoration: overline" id="linea_promociones">Promociones</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
@push('page_scripts')
|
@push('page_scripts')
|
||||||
<script>
|
<script>
|
||||||
class LineasTable extends TableHandler {
|
class LineasTable extends GroupedTableHandler {
|
||||||
ids = {
|
ids = {
|
||||||
lineas: 'lineas'
|
lineas: 'lineas',
|
||||||
|
promotions: 'linea_promociones'
|
||||||
}
|
}
|
||||||
constructor(commission) {
|
constructor(commission) {
|
||||||
super(commission)
|
super(commission)
|
||||||
@ -26,9 +27,12 @@
|
|||||||
draw({units, formatters}) {
|
draw({units, formatters}) {
|
||||||
const table = document.getElementById(this.ids.lineas)
|
const table = document.getElementById(this.ids.lineas)
|
||||||
const tbody = table.querySelector('tbody')
|
const tbody = table.querySelector('tbody')
|
||||||
|
tbody.innerHTML = ''
|
||||||
const lineas = Object.groupBy(units, unit => {
|
const lineas = Object.groupBy(units, unit => {
|
||||||
return [unit.proyecto_tipo_unidad.tipo_unidad.descripcion, unit.proyecto_tipo_unidad.nombre, unit.orientacion]
|
return [unit.proyecto_tipo_unidad.tipo_unidad.descripcion, unit.proyecto_tipo_unidad.nombre, unit.orientacion]
|
||||||
})
|
})
|
||||||
|
this.promotions.names = new Set()
|
||||||
|
this.promotions.values = []
|
||||||
Object.entries(lineas).sort(([linea1, unidades1], [linea2, unidades2]) => {
|
Object.entries(lineas).sort(([linea1, unidades1], [linea2, unidades2]) => {
|
||||||
const split1 = linea1.split(',')
|
const split1 = linea1.split(',')
|
||||||
const split2 = linea2.split(',')
|
const split2 = linea2.split(',')
|
||||||
@ -63,91 +67,24 @@
|
|||||||
`Desv: ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.broker)))}`
|
`Desv: ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.broker)))}`
|
||||||
].join("\n").replaceAll(' ', ' ')
|
].join("\n").replaceAll(' ', ' ')
|
||||||
|
|
||||||
let promotions = {}
|
const promotions = this.process().prices(prices)
|
||||||
prices.map(price => price.promotions).forEach(promotionArray => {
|
this.process().promotions().names(promotions)
|
||||||
promotionArray.forEach(p => {
|
this.process().promotions().values({promotions, formatters})
|
||||||
if (!Object.hasOwn(promotions, p.name)) {
|
|
||||||
promotions[p.name] = {
|
|
||||||
name: p.name,
|
|
||||||
type: p.type,
|
|
||||||
amount: [],
|
|
||||||
final: []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
promotions[p.name].amount.push(p.amount)
|
|
||||||
promotions[p.name].final.push(p.final)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
promotions = Object.values(promotions)
|
|
||||||
let subTable = false
|
|
||||||
if (promotions.length > 0) {
|
|
||||||
promotions = promotions.map(p => {
|
|
||||||
return {
|
|
||||||
name: p.name,
|
|
||||||
type: p.type,
|
|
||||||
amount: {
|
|
||||||
min: Math.min(...p.amount),
|
|
||||||
max: Math.max(...p.amount),
|
|
||||||
desv: Stat.standardDeviation(p.amount),
|
|
||||||
mean: Stat.mean(p.amount)
|
|
||||||
},
|
|
||||||
final: {
|
|
||||||
min: Math.min(...p.final),
|
|
||||||
max: Math.max(...p.final),
|
|
||||||
desv: Stat.standardDeviation(p.final),
|
|
||||||
mean: Stat.mean(p.final)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
subTable = document.createElement('table')
|
|
||||||
subTable.className = 'ui table'
|
|
||||||
const subTHead = document.createElement('thead')
|
|
||||||
promotions.forEach(p => {
|
|
||||||
subTHead.insertAdjacentHTML('beforeend', [
|
|
||||||
'<tr>',
|
|
||||||
'<th class="center aligned">Nombre</th>',
|
|
||||||
'<th class="center aligned">Forma</th>',
|
|
||||||
'<th class="right aligned">Precio Final</th>',
|
|
||||||
'</tr>'
|
|
||||||
].join("\n"))
|
|
||||||
})
|
|
||||||
const subTbody = document.createElement('tbody')
|
|
||||||
promotions.forEach(p => {
|
|
||||||
const amount_tooltip = [
|
|
||||||
`Min: ${p.type === 1 ? 'UF ' + formatters.ufs.format(p.amount.min) : formatters.percent.format(p.amount.min)}`,
|
|
||||||
`Max: ${p.type === 1 ? 'UF ' + formatters.ufs.format(p.amount.max) : formatters.percent.format(p.amount.max)}`,
|
|
||||||
`Desv: ${p.type === 1 ? 'UF ' + formatters.ufs.format(p.amount.desv) : formatters.percent.format(p.amount.desv)}`
|
|
||||||
].join("\n").replaceAll(' ', ' ')
|
|
||||||
const final_tooltip = [
|
|
||||||
`Min: UF ${formatters.ufs.format(p.final.min)}`,
|
|
||||||
`Max: UF ${formatters.ufs.format(p.final.max)}`,
|
|
||||||
`Desv: UF ${formatters.ufs.format(p.final.desv)}`
|
|
||||||
].join("\n").replaceAll(' ', ' ')
|
|
||||||
subTbody.insertAdjacentHTML('beforeend', [
|
|
||||||
'<tr>',
|
|
||||||
`<td class="center aligned">${p.name}</td>`,
|
|
||||||
`<td class="right aligned"><span data-tooltip="${amount_tooltip}" data-position="right center" data-variation="wide multiline">${p.type === 1 ? 'UF ' + formatters.ufs.format(p.amount.mean) : formatters.percent.format(p.amount.mean)}</td>`,
|
|
||||||
`<td class="right aligned"><span data-tooltip="${final_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(p.final.mean)}</td></td>`,
|
|
||||||
'</tr>'
|
|
||||||
].join("\n"))
|
|
||||||
})
|
|
||||||
subTable.appendChild(subTHead).appendChild(subTbody)
|
|
||||||
}
|
|
||||||
|
|
||||||
tbody.innerHTML += [
|
tbody.innerHTML += [
|
||||||
`<tr>`,
|
`<tr>`,
|
||||||
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
|
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
|
||||||
`<td class="center aligned"><span data-tooltip="${unidades[0].proyecto_tipo_unidad.tipologia}" data-position="right center">${parts[1]}</span></td>`,
|
`<td class="center aligned"><span data-tooltip="${unidades[0].proyecto_tipo_unidad.tipologia}" data-position="right center">${parts[1]}</span></td>`,
|
||||||
`<td class="center aligned">${orientacion}</td>`,
|
`<td class="center aligned">${orientacion}</td>`,
|
||||||
`<td class="center aligned">${unidades.length}</td>`,
|
`<td class="center aligned">${unidades.length}</td>`,
|
||||||
`<td class="right aligned"><span data-tooltip="${base_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))}</span></td>`,
|
`<td class="right aligned"><span data-tooltip="${base_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))}</span></td>`,
|
||||||
`<td class="right aligned"><span data-tooltip="${commission_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.commission)))}</span></td>`,
|
`<td class="right aligned"><span data-tooltip="${commission_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.commission)))}</span></td>`,
|
||||||
`<td class="right aligned"><span data-tooltip="${broker_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}</span></td>`,
|
`<td class="right aligned"><span data-tooltip="${broker_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}</span></td>`,
|
||||||
`<td class="right aligned">${subTable ? subTable.outerHTML : `UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}`}</td>`,
|
`<td class="right aligned promotions"></td>`,
|
||||||
`</tr>`
|
`</tr>`
|
||||||
].join("\n")
|
].join("\n")
|
||||||
})
|
})
|
||||||
|
this.build().promotions(table, tbody)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -14,15 +14,11 @@
|
|||||||
|
|
||||||
@push('page_scripts')
|
@push('page_scripts')
|
||||||
<script>
|
<script>
|
||||||
class TipoTable extends TableHandler {
|
class TipoTable extends GroupedTableHandler {
|
||||||
ids = {
|
ids = {
|
||||||
tipos: 'tipos',
|
tipos: 'tipos',
|
||||||
promotions: 'tipo_promociones'
|
promotions: 'tipo_promociones'
|
||||||
}
|
}
|
||||||
promotions = {
|
|
||||||
names: new Set(),
|
|
||||||
values: []
|
|
||||||
}
|
|
||||||
constructor(commission) {
|
constructor(commission) {
|
||||||
super(commission)
|
super(commission)
|
||||||
}
|
}
|
||||||
@ -70,130 +66,6 @@
|
|||||||
})
|
})
|
||||||
this.build().promotions(table, tbody)
|
this.build().promotions(table, tbody)
|
||||||
}
|
}
|
||||||
process() {
|
|
||||||
return {
|
|
||||||
prices: prices => {
|
|
||||||
let promotions = {}
|
|
||||||
prices.map(price => price.promotions).forEach(promotionArray => {
|
|
||||||
promotionArray.forEach(p => {
|
|
||||||
if (!Object.hasOwn(promotions, p.name)) {
|
|
||||||
promotions[p.name] = {
|
|
||||||
name: p.name,
|
|
||||||
type: p.type,
|
|
||||||
amount: [],
|
|
||||||
final: []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
promotions[p.name].amount.push(p.amount)
|
|
||||||
promotions[p.name].final.push(p.final)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
return promotions
|
|
||||||
},
|
|
||||||
promotions: () => {
|
|
||||||
return {
|
|
||||||
names: promotions => {
|
|
||||||
Object.keys(promotions).forEach(name => {
|
|
||||||
this.add().promotion().name(name)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
values: ({promotions, formatters}) => {
|
|
||||||
const temp = Object.values(promotions)
|
|
||||||
if (temp.length > 0) {
|
|
||||||
const data = temp.map(p => {
|
|
||||||
return {
|
|
||||||
name: p.name,
|
|
||||||
type: p.type,
|
|
||||||
amount: {
|
|
||||||
min: Math.min(...p.amount),
|
|
||||||
max: Math.max(...p.amount),
|
|
||||||
desv: Stat.standardDeviation(p.amount),
|
|
||||||
mean: Stat.mean(p.amount)
|
|
||||||
},
|
|
||||||
final: {
|
|
||||||
min: Math.min(...p.final),
|
|
||||||
max: Math.max(...p.final),
|
|
||||||
desv: Stat.standardDeviation(p.final),
|
|
||||||
mean: Stat.mean(p.final)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
this.add().promotion().values({promotions: data, formatters})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.promotions.values.push([])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add() {
|
|
||||||
return {
|
|
||||||
promotion: () => {
|
|
||||||
return {
|
|
||||||
name: name => {
|
|
||||||
this.promotions.names.add(name)
|
|
||||||
},
|
|
||||||
values: ({promotions, formatters}) => {
|
|
||||||
this.promotions.values.push(promotions.map(promotion => {
|
|
||||||
const amount_tooltip = [
|
|
||||||
`Min: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.min) : formatters.percent.format(promotion.amount.min)}`,
|
|
||||||
`Max: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.max) : formatters.percent.format(promotion.amount.max)}`,
|
|
||||||
`Desv: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.desv) : formatters.percent.format(promotion.amount.desv)}`
|
|
||||||
].join("\n").replaceAll(' ', ' ')
|
|
||||||
const final_tooltip = [
|
|
||||||
`Min: UF ${formatters.ufs.format(promotion.final.min)}`,
|
|
||||||
`Max: UF ${formatters.ufs.format(promotion.final.max)}`,
|
|
||||||
`Desv: UF ${formatters.ufs.format(promotion.final.desv)}`
|
|
||||||
].join("\n").replaceAll(' ', ' ')
|
|
||||||
return {
|
|
||||||
name: promotion.name,
|
|
||||||
value: [
|
|
||||||
`<td class="right aligned"><span data-tooltip="${amount_tooltip}" data-position="right center" data-variation="wide multiline">${promotion.type === 1 ? formatters.ufs.format(promotion.amount.mean) : formatters.percent.format(promotion.amount.mean)}</td>`,
|
|
||||||
`<td class="right aligned"><span data-tooltip="${final_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(promotion.final.mean)}</td></td>`,
|
|
||||||
].join("\n")
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
build() {
|
|
||||||
return {
|
|
||||||
promotions: (table, tbody) => {
|
|
||||||
if (this.promotions.names.size > 0) {
|
|
||||||
const title = document.getElementById(this.ids.promotions)
|
|
||||||
title.innerHTML = this.promotions.names.size > 0 ? Array.from(this.promotions.names)[0] : ''
|
|
||||||
title.setAttribute('colspan', '2')
|
|
||||||
if (this.promotions.names.size > 1) {
|
|
||||||
const thead = table.querySelector('thead')
|
|
||||||
Array.from(this.promotions.names).slice(1).forEach(name => {
|
|
||||||
thead.insertAdjacentHTML('beforeend', `<th class="right aligned" style="text-decoration: overline" colspan="2">${name}</th>`)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const trs = tbody.querySelectorAll('tr')
|
|
||||||
this.promotions.values.forEach((row, i) => {
|
|
||||||
const tr = trs[i]
|
|
||||||
const td = tr.querySelector('td.promotions')
|
|
||||||
if (row.length === 0) {
|
|
||||||
td.setAttribute('colspan', 2 * this.promotions.names.size)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
td.remove()
|
|
||||||
this.promotions.names.forEach(name => {
|
|
||||||
const index = row.findIndex(r => r.name === name)
|
|
||||||
if (index === -1) {
|
|
||||||
tr.insertAdjacentHTML('beforeend', '<td colspan="2"></td>')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tr.insertAdjacentHTML('beforeend', row[index].value)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<th class="right aligned">Comisión</th>
|
<th class="right aligned">Comisión</th>
|
||||||
<th class="right aligned">Precio Operador</th>
|
<th class="right aligned">Precio Operador</th>
|
||||||
<th class="right aligned">UF/m²</th>
|
<th class="right aligned">UF/m²</th>
|
||||||
<th class="right aligned">Promociones</th>
|
<th class="center aligned" id="unit_promotions">Promociones</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
@ -48,109 +48,158 @@
|
|||||||
'UF/m²',
|
'UF/m²',
|
||||||
'promociones',
|
'promociones',
|
||||||
]
|
]
|
||||||
|
set = {
|
||||||
|
table: false,
|
||||||
|
titles: false
|
||||||
|
}
|
||||||
|
table
|
||||||
constructor(commission) {
|
constructor(commission) {
|
||||||
super(commission)
|
super(commission)
|
||||||
|
}
|
||||||
const dto = structuredClone(datatables_defaults)
|
setup() {
|
||||||
dto.pageLength = 100
|
return {
|
||||||
dto.columnDefs = [
|
titles: promotions_names => {
|
||||||
{
|
if (this.set.titles || promotions_names.size === 0) {
|
||||||
target: ['tipo_order', 'unidad_order', 'tipologia', 'piso', 'orientacion', 'metros'].map(column => this.columns.indexOf(column)),
|
return
|
||||||
visible: false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
target: ['tipo'].map(column => this.columns.indexOf(column)),
|
|
||||||
orderData: ['tipo_order'].map(column => this.columns.indexOf(column)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
target: ['unidad'].map(column => this.columns.indexOf(column)),
|
|
||||||
orderData: ['unidad_order'].map(column => this.columns.indexOf(column)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
target: ['unidad', 'precio_base', 'commission', 'precio_operador', 'UF/m²', 'porcentaje', 'precio_final']
|
|
||||||
.map(column => this.columns.indexOf(column)),
|
|
||||||
className: 'dt-right right aligned'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
dto.order = ['tipo_order', 'unidad_order'].map(column => [this.columns.indexOf(column), 'asc'])
|
|
||||||
dto.language.searchBuilder = searchBuilder
|
|
||||||
dto.layout = {
|
|
||||||
top1Start: {
|
|
||||||
searchBuilder: {
|
|
||||||
columns: this.columns.filter(column => !['tipo_order', 'unidad_order'].includes(column))
|
|
||||||
.map(column => this.columns.indexOf(column)),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nameArray = Array.from(promotions_names)
|
||||||
|
|
||||||
|
this.columns.pop()
|
||||||
|
this.columns.push(`${nameArray[0].toLowerCase().replaceAll(' ', '_')}.amount`)
|
||||||
|
this.columns.push(`${nameArray[0].toLowerCase().replaceAll(' ', '_')}.final`)
|
||||||
|
|
||||||
|
const table = document.getElementById(this.ids.units)
|
||||||
|
const thead = table.querySelector('thead')
|
||||||
|
const tr = thead.querySelector('tr')
|
||||||
|
const th = tr.querySelector('th#unit_promotions')
|
||||||
|
th.innerHTML = `${nameArray[0]}<br />Porcentaje`
|
||||||
|
tr.insertAdjacentHTML('beforeend', `<th class="right aligned">${nameArray[0]}<br />Precio Final</th>`)
|
||||||
|
|
||||||
|
if (promotions_names.size > 1) {
|
||||||
|
nameArray.slice(1).forEach(name => {
|
||||||
|
this.columns.push(`${name.toLowerCase().replaceAll(' ', '_')}.amount`)
|
||||||
|
this.columns.push(`${name.toLowerCase().replaceAll(' ', '_')}.final`)
|
||||||
|
|
||||||
|
tr.insertAdjacentHTML('beforeend', `<th class="right aligned">${name}<br />Porcentaje</th>`)
|
||||||
|
tr.insertAdjacentHTML('beforeend', `<th class="right aligned">${name}<br />Precio Final</th>`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.set.titles = true
|
||||||
},
|
},
|
||||||
top1End: {
|
table: () => {
|
||||||
buttons: [
|
if (typeof this.table !== 'undefined' || this.set.table) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const dto = structuredClone(datatables_defaults)
|
||||||
|
dto.pageLength = 100
|
||||||
|
dto.columnDefs = [
|
||||||
{
|
{
|
||||||
extend: 'excelHtml5',
|
target: ['tipo_order', 'unidad_order', 'tipologia', 'piso', 'orientacion', 'metros'].map(column => this.columns.indexOf(column)),
|
||||||
className: 'green',
|
visible: false
|
||||||
text: 'Exportar a Excel <i class="file excel icon"></i>',
|
},
|
||||||
title: 'Lista de Precios - {{ $contract->broker->name }} - {{ $contract->project->descripcion }} - {{ (new DateTime())->format('Y-m-d') }}',
|
{
|
||||||
download: 'open',
|
target: ['tipo'].map(column => this.columns.indexOf(column)),
|
||||||
exportOptions: {
|
orderData: ['tipo_order'].map(column => this.columns.indexOf(column)),
|
||||||
columns: ['tipo', 'unidad', 'tipologia', 'piso', 'orientacion', 'metros_interior', 'metros_terraza', 'metros', 'metros_total', 'precio_operador', 'promociones']
|
},
|
||||||
.map(column => this.columns.indexOf(column)),
|
{
|
||||||
rows: (idx, data, node) => {
|
target: ['unidad'].map(column => this.columns.indexOf(column)),
|
||||||
return data[this.columns.indexOf('estado')] === 'Libre'
|
orderData: ['unidad_order'].map(column => this.columns.indexOf(column)),
|
||||||
},
|
},
|
||||||
format: {
|
{
|
||||||
body: (data, row, columnIdx, node) => {
|
target: ['unidad', 'precio_base', 'commission', 'precio_operador', 'UF/m²', 'porcentaje', 'precio_final']
|
||||||
if (typeof data === 'string' && data.includes('<span')) {
|
.map(column => this.columns.indexOf(column)),
|
||||||
return data.replace(/<span.*>(.*)<\/span>/, '$1')
|
className: 'dt-right right aligned'
|
||||||
}
|
|
||||||
if (['metros'].map(column => this.columns.indexOf(column)).includes(columnIdx)) {
|
|
||||||
return data.replaceAll('.', '').replaceAll(',', '.')
|
|
||||||
}
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
dto.order = ['tipo_order', 'unidad_order'].map(column => [this.columns.indexOf(column), 'asc'])
|
||||||
|
dto.language.searchBuilder = searchBuilder
|
||||||
|
const exportColumns = ['tipo', 'unidad', 'tipologia', 'piso', 'orientacion', 'metros_interior', 'metros_terraza', 'metros', 'metros_total', 'precio_operador', 'promociones']
|
||||||
|
if (typeof this.columns['promotions'] === 'undefined') {
|
||||||
|
exportColumns.pop()
|
||||||
|
this.columns.slice(this.columns.indexOf('UF/m²')).forEach(name => {
|
||||||
|
exportColumns.push(name)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
dto.layout = {
|
||||||
|
top1Start: {
|
||||||
|
searchBuilder: {
|
||||||
|
columns: this.columns.filter(column => !['tipo_order', 'unidad_order'].includes(column))
|
||||||
|
.map(column => this.columns.indexOf(column)),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
top1End: {
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
extend: 'excelHtml5',
|
||||||
|
className: 'green',
|
||||||
|
text: 'Exportar a Excel <i class="file excel icon"></i>',
|
||||||
|
title: 'Lista de Precios - {{ $contract->broker->name }} - {{ $contract->project->descripcion }} - {{ (new DateTime())->format('Y-m-d') }}',
|
||||||
|
download: 'open',
|
||||||
|
exportOptions: {
|
||||||
|
columns: exportColumns
|
||||||
|
.map(column => this.columns.indexOf(column)),
|
||||||
|
rows: (idx, data, node) => {
|
||||||
|
return data[this.columns.indexOf('estado')] === 'Libre'
|
||||||
|
},
|
||||||
|
format: {
|
||||||
|
body: (data, row, columnIdx, node) => {
|
||||||
|
if (typeof data === 'string' && data.includes('<span')) {
|
||||||
|
return data.replace(/<span.*>(.*)<\/span>/, '$1')
|
||||||
|
}
|
||||||
|
const formatColumns = ['metros', 'metros_interior', 'metros_terraza', 'metros_total']
|
||||||
|
if (this.set.titles) {
|
||||||
|
this.columns.filter(column => column.includes('.amount') || column.includes('.final')).forEach(name => {
|
||||||
|
formatColumns.push(name)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (formatColumns.map(column => this.columns.indexOf(column)).includes(columnIdx)) {
|
||||||
|
return data.replaceAll('.', '').replaceAll(',', '.')
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.table = $(`#${this.ids.units}`).DataTable(dto)
|
||||||
|
|
||||||
|
this.set.table = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$(`#${this.ids.units}`).DataTable(dto)
|
|
||||||
}
|
}
|
||||||
draw({units, formatters}) {
|
draw({units, formatters}) {
|
||||||
const table = $(`#${this.ids.units}`).DataTable()
|
|
||||||
table.clear()
|
|
||||||
const tableData = []
|
|
||||||
const prices = this.prices(units)
|
const prices = this.prices(units)
|
||||||
|
|
||||||
|
const promotions_names = new Set()
|
||||||
|
const tableData = []
|
||||||
units.forEach(unidad => {
|
units.forEach(unidad => {
|
||||||
const tipo = unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
|
const tipo = unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||||
const price = prices.find(p => p.id === unidad.id)
|
const price = prices.find(p => p.id === unidad.id)
|
||||||
|
|
||||||
let subTable = false
|
let promotions = []
|
||||||
|
price.promotions.forEach(p => {
|
||||||
|
if (Object.hasOwn(promotions, p.name)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
promotions[p.name] = {
|
||||||
|
name: p.name,
|
||||||
|
type: p.type,
|
||||||
|
amount: p.type === 1 ? 'UF ' + formatters.ufs.format(p.amount) : formatters.percent.format(p.amount),
|
||||||
|
final: `UF ${formatters.ufs.format(p.final)}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if (price.promotions.length > 0) {
|
Object.keys(promotions).forEach(name => {
|
||||||
subTable = document.createElement('table')
|
promotions_names.add(name)
|
||||||
subTable.className = 'ui table'
|
})
|
||||||
const subTHead = document.createElement('thead')
|
const temp = Object.values(promotions)
|
||||||
price.promotions.forEach(p => {
|
|
||||||
subTHead.insertAdjacentHTML('beforeend', [
|
|
||||||
'<tr>',
|
|
||||||
'<th class="center aligned">Nombre</th>',
|
|
||||||
'<th class="center aligned">Forma</th>',
|
|
||||||
'<th class="right aligned">Precio Final</th>',
|
|
||||||
'</tr>'
|
|
||||||
].join("\n"))
|
|
||||||
})
|
|
||||||
const subTBody = document.createElement('tbody')
|
|
||||||
price.promotions.forEach(p => {
|
|
||||||
subTBody.insertAdjacentHTML('beforeend', [
|
|
||||||
'<tr>',
|
|
||||||
`<td class="center aligned">${p.name}</td>`,
|
|
||||||
`<td class="right aligned">${p.type === 1 ? 'UF ' + formatters.ufs.format(p.amount) : formatters.percent.format(p.amount)}</td>`,
|
|
||||||
`<td class="right aligned">UF ${formatters.ufs.format(p.final)}</td>`,
|
|
||||||
'</tr>'
|
|
||||||
].join("\n"))
|
|
||||||
})
|
|
||||||
subTable.appendChild(subTHead).appendChild(subTBody)
|
|
||||||
}
|
|
||||||
|
|
||||||
tableData.push([
|
const data = [
|
||||||
unidad.sold ? `<span class="ui yellow text">Vendida</span>` : 'Libre',
|
unidad.sold ? `<span class="ui yellow text">Vendida</span>` : 'Libre',
|
||||||
tipo.charAt(0).toUpperCase() + tipo.slice(1),
|
tipo.charAt(0).toUpperCase() + tipo.slice(1),
|
||||||
unidad.proyecto_tipo_unidad.tipo_unidad.orden,
|
unidad.proyecto_tipo_unidad.tipo_unidad.orden,
|
||||||
@ -167,9 +216,33 @@
|
|||||||
formatters.percent.format(price.commission ?? 0),
|
formatters.percent.format(price.commission ?? 0),
|
||||||
'UF ' + formatters.ufs.format(price.broker ?? 0),
|
'UF ' + formatters.ufs.format(price.broker ?? 0),
|
||||||
formatters.ufs.format(price.broker / unidad.proyecto_tipo_unidad.vendible),
|
formatters.ufs.format(price.broker / unidad.proyecto_tipo_unidad.vendible),
|
||||||
subTable ? subTable.outerHTML : 'UF ' + formatters.ufs.format(price.broker ?? 0),
|
''
|
||||||
])
|
]
|
||||||
|
|
||||||
|
if (temp.length > 0) {
|
||||||
|
data.pop()
|
||||||
|
temp.forEach((p, i) => {
|
||||||
|
data.push(p.amount)
|
||||||
|
data.push(p.final)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
if (promotions_names.size > 0) {
|
||||||
|
Array.from(promotions_names).forEach(name => {
|
||||||
|
data.push('')
|
||||||
|
data.push('')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tableData.push(data)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.setup().titles(promotions_names)
|
||||||
|
this.setup().table()
|
||||||
|
|
||||||
|
const table = this.table
|
||||||
|
table.clear()
|
||||||
|
|
||||||
table.rows.add(tableData)
|
table.rows.add(tableData)
|
||||||
table.draw()
|
table.draw()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user