Se agregan columnas y el calculo de promociones de tipo fijo

This commit is contained in:
Juan Pablo Vial
2025-04-08 19:04:46 -04:00
parent 76f69f3bda
commit 3c2b486083
2 changed files with 32 additions and 14 deletions

View File

@ -20,12 +20,18 @@
prices(units) { prices(units) {
const prices = [] const prices = []
units.forEach(unit => { units.forEach(unit => {
const price = unit.precio?.valor ?? 0 let price = unit.precio?.valor ?? 0
let amount = 1 let amount = 1
let diff = 0
unit.promotions?.forEach(promotion => { unit.promotions?.forEach(promotion => {
if (promotion.type === 1) {
diff += promotion.amount
return
}
amount /= 1/(1 - promotion.amount) amount /= 1/(1 - promotion.amount)
}) })
amount = 1 - amount amount = 1 - amount
price += diff
prices.push({ prices.push({
id: unit.id, id: unit.id,
base: price, base: price,

View File

@ -1,15 +1,19 @@
<table class="ui table" id="unidades"> <table class="ui table" id="unidades">
<thead> <thead>
<tr> <tr>
<th>Estado</th>
<th>Tipo</th> <th>Tipo</th>
<th>Tipo Order</th> <th>Tipo Order</th>
<th class="right aligned">Unidad</th> <th class="right aligned">Unidad</th>
<th>Unidad Orden</th> <th>Unidad Orden</th>
<th>Tipología</th>
<th>Piso</th>
<th>Orientación</th>
<th>m&#0178;</th> <th>m&#0178;</th>
<th>Estado</th>
<th class="right aligned">Precio Base</th> <th class="right aligned">Precio Base</th>
<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/</th>
<th class="right aligned">Porcentaje</th> <th class="right aligned">Porcentaje</th>
<th class="right aligned">Precio Final</th> <th class="right aligned">Precio Final</th>
</tr> </tr>
@ -24,15 +28,19 @@
units: 'unidades', units: 'unidades',
} }
columns = [ columns = [
'estado',
'tipo', 'tipo',
'tipo_order', 'tipo_order',
'unidad', 'unidad',
'unidad_order', 'unidad_order',
'tipologia',
'piso',
'orientacion',
'metros', 'metros',
'estado',
'precio_base', 'precio_base',
'commission', 'commission',
'precio_operador', 'precio_operador',
'UF/m²',
'porcentaje', 'porcentaje',
'precio_final', 'precio_final',
] ]
@ -43,24 +51,24 @@
dto.pageLength = 100 dto.pageLength = 100
dto.columnDefs = [ dto.columnDefs = [
{ {
target: [1, 3], target: ['tipo_order', 'unidad_order', 'tipologia', 'piso', 'orientacion', 'metros'].map(column => this.columns.indexOf(column)),
visible: false visible: false
}, },
{ {
target: 0, target: ['tipo'].map(column => this.columns.indexOf(column)),
orderData: 1 orderData: ['tipo_order'].map(column => this.columns.indexOf(column)),
}, },
{ {
target: 2, target: ['unidad'].map(column => this.columns.indexOf(column)),
orderData: 3 orderData: ['unidad_order'].map(column => this.columns.indexOf(column)),
}, },
{ {
target: ['metros', 'precio_base', 'commission', 'precio_operador', 'porcentaje', 'precio_final'] target: ['unidad', 'precio_base', 'commission', 'precio_operador', 'UF/m²', 'porcentaje', 'precio_final']
.map(column => this.columns.indexOf(column)), .map(column => this.columns.indexOf(column)),
className: 'dt-right right aligned' className: 'dt-right right aligned'
} }
] ]
dto.order = [[1, 'asc'], [3, 'asc']] dto.order = ['tipo_order', 'unidad_order'].map(column => [this.columns.indexOf(column), 'asc'])
dto.language.searchBuilder = searchBuilder dto.language.searchBuilder = searchBuilder
dto.layout = { dto.layout = {
top1Start: { top1Start: {
@ -78,17 +86,17 @@
title: 'Lista de Precios - {{ $contract->broker->name }} - {{ $contract->project->descripcion }} - {{ (new DateTime())->format('Y-m-d') }}', title: 'Lista de Precios - {{ $contract->broker->name }} - {{ $contract->project->descripcion }} - {{ (new DateTime())->format('Y-m-d') }}',
download: 'open', download: 'open',
exportOptions: { exportOptions: {
columns: ['tipo', 'unidad', 'metros', 'commission', 'precio_operador', 'porcentaje', 'precio_final'] columns: ['tipo', 'unidad', 'tipologia', 'piso', 'orientacion', 'metros', 'commission', 'precio_operador', 'porcentaje', 'precio_final']
.map(column => this.columns.indexOf(column)), .map(column => this.columns.indexOf(column)),
rows: (idx, data, node) => { rows: (idx, data, node) => {
return data[this.columns.indexOf('estado')] === 'Disponible' return data[this.columns.indexOf('estado')] === 'Libre'
}, },
format: { format: {
body: (data, row, columnIdx, node) => { body: (data, row, columnIdx, node) => {
if (typeof data === 'string' && data.includes('<span')) { if (typeof data === 'string' && data.includes('<span')) {
return data.replace(/<span.*>(.*)<\/span>/, '$1') return data.replace(/<span.*>(.*)<\/span>/, '$1')
} }
if (columnIdx === this.columns.indexOf('metros')) { if (['metros'].map(column => this.columns.indexOf(column)).includes(columnIdx)) {
return data.replaceAll('.', '').replaceAll(',', '.') return data.replaceAll('.', '').replaceAll(',', '.')
} }
return data return data
@ -110,15 +118,19 @@
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)
tableData.push([ tableData.push([
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,
unidad.descripcion, unidad.descripcion,
unidad.descripcion.padStart(4, '0'), unidad.descripcion.padStart(4, '0'),
unidad.proyecto_tipo_unidad.tipologia,
unidad.piso,
unidad.orientacion,
formatters.ufs.format(unidad.proyecto_tipo_unidad.vendible) ?? 0, formatters.ufs.format(unidad.proyecto_tipo_unidad.vendible) ?? 0,
unidad.sold ? '<span class="ui yellow text">Vendida</span>' : 'Disponible',
'UF ' + formatters.ufs.format(price.base ?? 0), 'UF ' + formatters.ufs.format(price.base ?? 0),
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.percent.format(price.amount ?? 0), formatters.percent.format(price.amount ?? 0),
'UF ' + formatters.ufs.format(price.final ?? 0), 'UF ' + formatters.ufs.format(price.final ?? 0),
unidad.promotion?.start_date ?? '', unidad.promotion?.start_date ?? '',