diff --git a/app/resources/views/proyectos/brokers/contracts/show.blade.php b/app/resources/views/proyectos/brokers/contracts/show.blade.php
index 3952d8c..d0d0d14 100644
--- a/app/resources/views/proyectos/brokers/contracts/show.blade.php
+++ b/app/resources/views/proyectos/brokers/contracts/show.blade.php
@@ -18,30 +18,33 @@
}
draw() {}
prices(units) {
- const prices = []
- units.forEach(unit => {
- let price = unit.valor ?? (unit.precio?.valor ?? 0)
- let amount = 1
- let diff = 0
- unit.promotions?.forEach(promotion => {
+ return units.map(unit => {
+ let price = unit.valor ?? (unit.precio?.valor ?? 0)
+ const broker = price / (1 - this.commission)
+ const promotions = unit.promotions?.map(promotion => {
if (promotion.type === 1) {
- diff += promotion.amount
- return
+ return {
+ name: promotion.description,
+ type: promotion.type,
+ amount: promotion.amount,
+ final: broker + promotion.amount
+ }
}
- amount /= 1/(1 - promotion.amount)
- })
- amount = 1 - amount
- price += diff
- prices.push({
+ return {
+ name: promotion.description,
+ type: promotion.type,
+ amount: promotion.amount,
+ final: broker / (1 - promotion.amount)
+ }
+ }) ?? []
+ return {
id: unit.id,
base: price,
commission: this.commission,
- broker: price / (1 - this.commission),
- amount,
- final: price / (1 - this.commission) / (1 - amount)
- })
+ broker,
+ promotions
+ }
})
- return prices
}
}
diff --git a/app/resources/views/proyectos/brokers/contracts/show/linea.blade.php b/app/resources/views/proyectos/brokers/contracts/show/linea.blade.php
index eb06fb8..8ef7067 100644
--- a/app/resources/views/proyectos/brokers/contracts/show/linea.blade.php
+++ b/app/resources/views/proyectos/brokers/contracts/show/linea.blade.php
@@ -7,7 +7,6 @@
Cantidad |
Precio Base |
Comisión |
- Porcentaje |
Precio Operador |
Precio Final |
@@ -63,16 +62,78 @@
`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(' ', ' ')
+
+ 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', [
+ '',
+ 'Nombre | ',
+ 'Forma | ',
+ 'Precio Final | ',
+ '
'
+ ].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', [
+ '',
+ `${p.name} | `,
+ `${p.type === 1 ? 'UF ' + formatters.ufs.format(p.amount.mean) : formatters.percent.format(p.amount.mean)} | `,
+ `UF ${formatters.ufs.format(p.final.mean)} | `,
+ '
'
+ ].join("\n"))
+ })
+ subTable.appendChild(subTHead).appendChild(subTbody)
+ }
tbody.innerHTML += [
``,
@@ -83,8 +144,7 @@
`UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))} | `,
`${formatters.percent.format(Stat.mean(prices.map(p => p.commission)))} | `,
`UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))} | `,
- `${formatters.percent.format(Stat.mean(prices.map(p => p.amount)))} | `,
- `UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.final)))} | `,
+ `${subTable ? subTable.outerHTML : `UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}`} | `,
`
`
].join("\n")
})
diff --git a/app/resources/views/proyectos/brokers/contracts/show/tipo.blade.php b/app/resources/views/proyectos/brokers/contracts/show/tipo.blade.php
index 3e67f1a..481c4e5 100644
--- a/app/resources/views/proyectos/brokers/contracts/show/tipo.blade.php
+++ b/app/resources/views/proyectos/brokers/contracts/show/tipo.blade.php
@@ -6,8 +6,7 @@
Precio Base |
Comisión |
Precio Operador |
- Porcentaje |
- Precio Final |
+ Promociones |
@@ -46,16 +45,77 @@
`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(' ', ' ')
+
+ 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', [
+ '',
+ 'Nombre | ',
+ 'Forma | ',
+ 'Precio Final | ',
+ '
'
+ ].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', [
+ '',
+ `${p.name} | `,
+ `${p.type === 1 ? formatters.ufs.format(p.amount.mean) : formatters.percent.format(p.amount.mean)} | `,
+ `UF ${formatters.ufs.format(p.final.mean)} | `,
+ '
'
+ ].join("\n"))
+ })
+ subTable.appendChild(subTHead).appendChild(subTbody)
+ }
tbody.innerHTML += [
``,
@@ -64,8 +124,7 @@
`UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))} | `,
`${formatters.percent.format(Stat.mean(prices.map(p => p.commission)))} | `,
`UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))} | `,
- `${formatters.percent.format(Stat.mean(prices.map(p => p.amount)))} | `,
- `UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.final)))} | `,
+ `${subTable ? subTable.outerHTML : `UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}`} | `,
`
`
].join("\n")
})
diff --git a/app/resources/views/proyectos/brokers/contracts/show/unidades.blade.php b/app/resources/views/proyectos/brokers/contracts/show/unidades.blade.php
index c55c3d1..528e594 100644
--- a/app/resources/views/proyectos/brokers/contracts/show/unidades.blade.php
+++ b/app/resources/views/proyectos/brokers/contracts/show/unidades.blade.php
@@ -9,13 +9,15 @@
Tipología |
Piso |
Orientación |
- m² |
+ m² Interior |
+ m² Terraza |
+ m² Vendibles |
+ m² Total |
Precio Base |
Comisión |
Precio Operador |
UF/m² |
- Porcentaje |
- Precio Final |
+ Promociones |
@@ -36,13 +38,15 @@
'tipologia',
'piso',
'orientacion',
+ 'metros_interior',
+ 'metros_terraza',
'metros',
+ 'metros_total',
'precio_base',
'commission',
'precio_operador',
'UF/m²',
- 'porcentaje',
- 'precio_final',
+ 'promociones',
]
constructor(commission) {
super(commission)
@@ -86,7 +90,7 @@
title: 'Lista de Precios - {{ $contract->broker->name }} - {{ $contract->project->descripcion }} - {{ (new DateTime())->format('Y-m-d') }}',
download: 'open',
exportOptions: {
- columns: ['tipo', 'unidad', 'tipologia', 'piso', 'orientacion', 'metros', 'precio_operador', 'porcentaje', 'precio_final']
+ 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) => {
return data[this.columns.indexOf('estado')] === 'Libre'
@@ -117,6 +121,35 @@
units.forEach(unidad => {
const tipo = unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
const price = prices.find(p => p.id === unidad.id)
+
+ let subTable = false
+
+ if (price.promotions.length > 0) {
+ subTable = document.createElement('table')
+ subTable.className = 'ui table'
+ const subTHead = document.createElement('thead')
+ price.promotions.forEach(p => {
+ subTHead.insertAdjacentHTML('beforeend', [
+ '',
+ 'Nombre | ',
+ 'Forma | ',
+ 'Precio Final | ',
+ '
'
+ ].join("\n"))
+ })
+ const subTBody = document.createElement('tbody')
+ price.promotions.forEach(p => {
+ subTBody.insertAdjacentHTML('beforeend', [
+ '',
+ `${p.name} | `,
+ `${p.type === 1 ? 'UF ' + formatters.ufs.format(p.amount) : formatters.percent.format(p.amount)} | `,
+ `UF ${formatters.ufs.format(p.final)} | `,
+ '
'
+ ].join("\n"))
+ })
+ subTable.appendChild(subTHead).appendChild(subTBody)
+ }
+
tableData.push([
unidad.sold ? `Vendida` : 'Libre',
tipo.charAt(0).toUpperCase() + tipo.slice(1),
@@ -126,15 +159,15 @@
unidad.proyecto_tipo_unidad.tipologia,
unidad.piso,
unidad.orientacion,
+ formatters.ufs.format(unidad.proyecto_tipo_unidad.util) ?? 0,
+ formatters.ufs.format(unidad.proyecto_tipo_unidad.terraza) ?? 0,
formatters.ufs.format(unidad.proyecto_tipo_unidad.vendible) ?? 0,
+ formatters.ufs.format(unidad.proyecto_tipo_unidad.superficie) ?? 0,
'UF ' + formatters.ufs.format(price.base ?? 0),
formatters.percent.format(price.commission ?? 0),
'UF ' + formatters.ufs.format(price.broker ?? 0),
formatters.ufs.format(price.broker / unidad.proyecto_tipo_unidad.vendible),
- formatters.percent.format(price.amount ?? 0),
- 'UF ' + formatters.ufs.format(price.final ?? 0),
- unidad.promotion?.start_date ?? '',
- unidad.promotion?.end_date ?? '',
+ subTable ? subTable.outerHTML : 'UF ' + formatters.ufs.format(price.broker ?? 0),
])
})
table.rows.add(tableData)