95 lines
6.0 KiB
PHP
95 lines
6.0 KiB
PHP
<table class="ui table" id="lineas">
|
|
<thead>
|
|
<tr>
|
|
<th>Tipo</th>
|
|
<th class="center aligned">Línea</th>
|
|
<th class="center aligned">Orientación</th>
|
|
<th class="center aligned">Cantidad</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">Porcentaje</th>
|
|
<th class="right aligned" style="text-decoration: overline">Precio Operador</th>
|
|
<th class="right aligned" style="text-decoration: overline">Precio Final</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
|
|
@push('page_scripts')
|
|
<script>
|
|
class LineasTable extends TableHandler {
|
|
ids = {
|
|
lineas: 'lineas'
|
|
}
|
|
constructor(commission) {
|
|
super(commission)
|
|
}
|
|
draw({units, formatters}) {
|
|
const table = document.getElementById(this.ids.lineas)
|
|
const tbody = table.querySelector('tbody')
|
|
const lineas = Object.groupBy(units, unit => {
|
|
return [unit.proyecto_tipo_unidad.tipo_unidad.descripcion, unit.proyecto_tipo_unidad.nombre, unit.orientacion]
|
|
})
|
|
Object.entries(lineas).sort(([linea1, unidades1], [linea2, unidades2]) => {
|
|
const split1 = linea1.split(',')
|
|
const split2 = linea2.split(',')
|
|
const ct = unidades1[0].proyecto_tipo_unidad.tipo_unidad.orden - unidades2[0].proyecto_tipo_unidad.tipo_unidad.orden
|
|
if (ct === 0) {
|
|
const cl = split1[1].localeCompare(split2[1])
|
|
if (cl === 0) {
|
|
return split1[2].localeCompare(split2[2])
|
|
}
|
|
return cl
|
|
}
|
|
return ct
|
|
}).forEach(([linea, unidades]) => {
|
|
const parts = linea.split(',')
|
|
const tipo = parts[0]
|
|
const orientacion = parts[2]
|
|
const prices = this.prices(unidades)
|
|
|
|
const base_tooltip = [
|
|
`Min: UF ${formatters.ufs.format(Math.min(...prices.map(p => p.base)))}`,
|
|
`Max: UF ${formatters.ufs.format(Math.max(...prices.map(p => p.base)))}`,
|
|
`Desv: UF ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.base)))}`
|
|
].join("\n").replaceAll(' ', ' ')
|
|
const commission_tooltip = [
|
|
`Min: ${formatters.percent.format(Math.min(...prices.map(p => p.commission)))}`,
|
|
`Max: ${formatters.percent.format(Math.max(...prices.map(p => p.commission)))}`,
|
|
`Desv: ${formatters.percent.format(Stat.standardDeviation(prices.map(p => p.commission)))}`
|
|
].join("\n").replaceAll(' ', ' ')
|
|
const broker_tooltip = [
|
|
`Min: ${formatters.ufs.format(Math.min(...prices.map(p => p.broker)))}`,
|
|
`Max: ${formatters.ufs.format(Math.max(...prices.map(p => p.broker)))}`,
|
|
`Desv: ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.broker)))}`
|
|
].join("\n").replaceAll(' ', ' ')
|
|
const amount_tooltip = [
|
|
`Min: ${formatters.percent.format(Math.min(...prices.map(p => p.amount)))}`,
|
|
`Max: ${formatters.percent.format(Math.max(...prices.map(p => p.amount)))}`,
|
|
`Desv: ${formatters.percent.format(Stat.standardDeviation(prices.map(p => p.amount)))}`
|
|
].join("\n").replaceAll(' ', ' ')
|
|
const final_tooltip = [
|
|
`Min: UF ${formatters.ufs.format(Math.min(...prices.map(p => p.final)))}`,
|
|
`Max: UF ${formatters.ufs.format(Math.max(...prices.map(p => p.final)))}`,
|
|
`Desv: UF ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.final)))}`
|
|
].join("\n").replaceAll(' ', ' ')
|
|
|
|
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"><span data-tooltip="${amount_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.amount)))}</span></td>`,
|
|
`<td class="right aligned"><span data-tooltip="${final_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.final)))}</span></td>`,
|
|
`</tr>`
|
|
].join("\n")
|
|
})
|
|
}
|
|
}
|
|
</script>
|
|
@endpush
|