Promociones en misma tabla para tipo
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
<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">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>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
@ -16,9 +16,10 @@
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class LineasTable extends TableHandler {
|
||||
class LineasTable extends GroupedTableHandler {
|
||||
ids = {
|
||||
lineas: 'lineas'
|
||||
lineas: 'lineas',
|
||||
promotions: 'linea_promociones'
|
||||
}
|
||||
constructor(commission) {
|
||||
super(commission)
|
||||
@ -26,9 +27,12 @@
|
||||
draw({units, formatters}) {
|
||||
const table = document.getElementById(this.ids.lineas)
|
||||
const tbody = table.querySelector('tbody')
|
||||
tbody.innerHTML = ''
|
||||
const lineas = Object.groupBy(units, unit => {
|
||||
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]) => {
|
||||
const split1 = linea1.split(',')
|
||||
const split2 = linea2.split(',')
|
||||
@ -63,91 +67,24 @@
|
||||
`Desv: ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.broker)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
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)
|
||||
}
|
||||
const promotions = this.process().prices(prices)
|
||||
this.process().promotions().names(promotions)
|
||||
this.process().promotions().values({promotions, formatters})
|
||||
|
||||
tbody.innerHTML += [
|
||||
`<tr>`,
|
||||
`<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">${orientacion}</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="${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">${subTable ? subTable.outerHTML : `UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}`}</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">${orientacion}</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="${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 promotions"></td>`,
|
||||
`</tr>`
|
||||
].join("\n")
|
||||
})
|
||||
this.build().promotions(table, tbody)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user